Page 1 of 1

No Info being picked up from DB

Posted: Wed Jan 29, 2003 1:03 pm
by don_assi
Hi All...
I'm new to all this stuff...

The following file links through to a main file that allows access to the MySQL DB... but it is not picking up anything from the DB... is there something wrong with the code... would appreciate your help.

Code: Select all

<html>
<head>
</head>
<body>
<?

require("Cart.php");
DBinfo();
Brand();
Root();
mysql_connect("$DBHost","$DBUser","$DBPass");
mysql_select_db($DBName);

if ($UID !=   "") &#123;
$result=mysql_query("SELECT * FROM Users WHERE User='$UID'");
$num=mysql_num_rows($result);
if ($num ==   "0") &#123;
$dt=date(  "YmdHis");
$UID=  "$dt$REMOTE_ADDR";
$date=date(  "z");
mysql_query("INSERT INTO Users VALUES ('$UID','$date')");
Header(  "Location: $PHP_SELF?CA=$CA&UID=$UID");
&#125;
&#125;

if ($UID ==   "") &#123;
$dt=date(  "YmdHis");
$UID=  "$dt$REMOTE_ADDR";
$date=date(  "z");
mysql_query("INSERT INTO Users VALUES ('$UID','$date')");

&#125;


commonHeader("$Company","Select an item");
$result=mysql_query("SELECT * FROM Items WHERE Category='$CA' ORDER BY ItemName");
fontFace("Arial","Select an item:<br><br>");
echo "<ul>";
while ($row  =  mysql_fetch_row($result)) &#123;
$IS=$row&#1111;0];
$IN=$row&#1111;1];
$ID=$row&#1111;2];
$IC=$row&#1111;3];
$Ca=$row&#1111;4];
$SC=$row&#1111;5];
$II=$row&#1111;6];
fontFace("Arial","<li><a href='$Relative/description.php?II=$II&UID=$UID'>$IN</a>");
if ($ID != "") &#123;
fontFace("Arial"," - $ID"); &#125;
echo "</li>";
        &#125;
echo "</ul>";

commonFooter($Relative,$UID);
?></body></html>
This is the main file cart.php:

Code: Select all

<?/* Replace these variables with information about your company */
$Company ="donassi co";
$Address1="555 Any St.";
$Address2="PO Box 3";
$City    ="London";
$State   ="UK";
$Zip     ="BR7 6EZ";
$Phone   ="+44 077 590 13806";
$Web     ="http://www.yoursite.com/";
$Email   ="don_assi@postmaster.co.uk";
$NoShipping = "Shipping Extra";
function Brand() &#123;
global $Company,$Address1,$Address2,$City,$State,$Zip,$Phone,$Web,$Email,$NoShipping;
&#125;

/* Replace these variables with information for connecting to your
database server */
$DBHost="hermes";
$DBUser="gassi01";
$DBPass="Capone77";
$DBName="gassi01db";
function DBInfo() &#123;
global $DBHost,$DBUser,$DBPass,$DBName;
&#125;

/* Replace these variables with the absolute and relative paths to your
MyCart scripts */
$WebRoot="home/gassi01/public_www/Cart";
$Relative="/~gassi01/Cart";
$WebHost="hermes.dcs.bbk.ac.uk";
function Root() &#123;
global $WebRoot,$Relative,$WebHost;
&#125;

function redFont($font,$text) &#123;
echo "<FONT FACE="$font" COLOR="red">$text</FONT>";
&#125;

function blueFont($font,$text) &#123;
echo "<FONT FACE="$font" COLOR="blue">$text</FONT>";
&#125;

function colorFont($color,$font,$text) &#123;
echo "<FONT FACE="$font" COLOR="$color">$text</FONT>";
&#125;

function fontFace($font,$text) &#123;
echo "<FONT FACE="$font">$text</FONT>";
&#125;

function fontSize($size,$color,$font,$text) &#123;
echo "<FONT FACE="$font" COLOR="$color" SIZE="$size">$text</FONT>";
&#125;

function commonHeader($Company,$title) &#123;
echo "<HTML><TITLE>$Company Shopping Cart - $title</TITLE><BODY BGCOLOR="#FFFFFF">";
&#125;

function receiptHeader($Company,$title) &#123;
echo "<HTML><TITLE>$Company Receipt - $title</TITLE><BODY BGCOLOR="#FFFFFF">";
&#125;

function commonFooter($Relative,$UID) &#123;
echo "<center><br><br><hr width="70%"><br>";
echo "<b><a href="$Relative/checkout.php?UID=$UID">Go To The Check Out Stand</a></b><br><br>";
echo "<b><a href="$Relative/viewCart.php?UID=$UID">View The Contents Of Your Cart</a></b><br><br>";
fontFace("Arial","<a href="$Relative/index.php?UID=$UID">Our Catalog</a>");
fontFace("Arial"," | <a href="/">Home</a>");
echo "<br><br></center></BODY></HTML>";
&#125;

function adminFooter($Relative) &#123;
echo "<center><br><br><hr width="70%"><br>";
fontFace("Arial"," | <a href="$Relative">Our Catalog</a>");
fontFace("Arial"," | <a href="$Relative/admin/">Shopping Cart Admin</a>");
fontFace("Arial"," | <a href="http://modems.rosenet.net/mysql/">MySQL Utilities</a>");
fontFace("Arial"," | <a href="http://www.rosenet.net/">Rosenet</a>");
echo "<br><br></center></BODY></HTML>";
&#125;

function receiptFooter($Company) &#123;
echo "<br><br><center>";
fontFace("Arial","Thank you for ordering from <b>$Company</b>");
echo "</center><br><br>";
&#125;?>
Would really appreciate your help...
thanks don_assi

Posted: Wed Jan 29, 2003 1:48 pm
by evilcoder
$UID = "$dt$REMOTE_ADDR"

In your database is UID Set to auto_increment?

Usually you dont set a UID to firstly the data, then to an IP Address.

Actually, i'd be more inclined to do like:

$UID = $dt . $REMOTE_ADDR;

But still, it seems a little unorthodox.

You could also try putting some error reporting in there:

Code: Select all

<?php
if ( !$num )
{ 
  echo mysql_error() . " <-- Select Failed";
}
if ( $num == 0 )
{
$dt=date(  "YmdHis" ); 
$UID=  $dt . $REMOTE_ADDR; 
$date=date(  "z" ); 
$Insert = mysql_query( "INSERT INTO Users VALUES ('$UID','$date' )" ); 
if ( !$Insert )
{
  echo mysql_error() . "<-- Insert Failed";
}
else
{
Header(  "Location: $PHP_SELF?CA=$CA&UID=$UID"); 
}
} 

?>