mithilesh
12-26-2001, 04:32 PM
I had used a variable in PHP and it is working properly when I execute the page and give me required result but it shows some warninig.
Warning: Undefined variable: gtotal in d:\mith\php\cart\cart.php on line 39
I couldn't understand the problem.So please if u can then give me some tips for it.
CODE :-
<?
// database connect
$dbh = mysql_connect("localhost","mithilesh","classic") or die('I cannot connect to the database.');
mysql_select_db("cartnew");
// query to get the customers cart contents
$result = mysql_query("select * from customers where cartID = '$cartID'",$dbh);
echo "<table bgcolor=\"$middle\" cellpadding=0 cellspacing=0 border=1>
<tr><td>Remove</td>
<td>Name</td>
<td>Quantity</td>
<td>Price</td>
<td>Total</td>
</tr>";
// loop to display the results of the query, generates table of
// customers cart contents
for ($i = 0; $i < mysql_numrows($result); $i++) {
$row = mysql_fetch_row($result);
$gtotal += $row[6];
echo "<tr>
<td align=center><font size=-1><form method=post action=cart.php?d=remove&cartID=$cartID>
<input type=hidden value=\"$row[1]\" name=\"rem\">
<input type=submit value=\"Remove\"></form></td>
<td>$row[2]</td>
<td><form method=post action=cart.php?d=quantity&cartID=$cartID>
<input type=text size=2 maxlength=2 value=\"$row[5]\" name=\"quantity\">
<input type=hidden value=\"$row[1]\" name=\"prod_id\">
<input type=hidden value=\"$cartID\" name=\"cartID\">
<input type=hidden value=\"$row[3]\" name=\"price\">
<input type=submit value=\"Update\"></form>
</td><td>\$$row[3]</td><td>\$$row[6].00</td></tr>";
}
Warning: Undefined variable: gtotal in d:\mith\php\cart\cart.php on line 39
I couldn't understand the problem.So please if u can then give me some tips for it.
CODE :-
<?
// database connect
$dbh = mysql_connect("localhost","mithilesh","classic") or die('I cannot connect to the database.');
mysql_select_db("cartnew");
// query to get the customers cart contents
$result = mysql_query("select * from customers where cartID = '$cartID'",$dbh);
echo "<table bgcolor=\"$middle\" cellpadding=0 cellspacing=0 border=1>
<tr><td>Remove</td>
<td>Name</td>
<td>Quantity</td>
<td>Price</td>
<td>Total</td>
</tr>";
// loop to display the results of the query, generates table of
// customers cart contents
for ($i = 0; $i < mysql_numrows($result); $i++) {
$row = mysql_fetch_row($result);
$gtotal += $row[6];
echo "<tr>
<td align=center><font size=-1><form method=post action=cart.php?d=remove&cartID=$cartID>
<input type=hidden value=\"$row[1]\" name=\"rem\">
<input type=submit value=\"Remove\"></form></td>
<td>$row[2]</td>
<td><form method=post action=cart.php?d=quantity&cartID=$cartID>
<input type=text size=2 maxlength=2 value=\"$row[5]\" name=\"quantity\">
<input type=hidden value=\"$row[1]\" name=\"prod_id\">
<input type=hidden value=\"$cartID\" name=\"cartID\">
<input type=hidden value=\"$row[3]\" name=\"price\">
<input type=submit value=\"Update\"></form>
</td><td>\$$row[3]</td><td>\$$row[6].00</td></tr>";
}
