I have all parts of my shopping system working now for the most part, but since the start I have been getting an error when viewing the shopping cart with nothing in it. I know the code is missing something, which is why I'm posting this in hope someone can help me out. If you visit this page you will see the error. http://jcs5325.aisites.com/shoppingcart.php
Here is that page(ignore all the stm lines, it's part of my menu):
<?php
session_start();
if ((isset($HTTP_COOKIE_VARS)) || (isset($HTTP_SESSION_VARS)) || (isset($HTTP_GET_VARS))) {
extract ($HTTP_COOKIE_VARS);
extract ($HTTP_SESSION_VARS);
extract ($HTTP_GET_VARS);
}
reset ($HTTP_COOKIE_VARS);
reset ($HTTP_SESSION_VARS);
reset ($HTTP_GET_VARS);
//if (!(@session_is_registered($HTTP_SESSION_VARS['cart']))) {
//if (!($HTTP_SESSION_VARS['cart'] == "")) {
/*
$cart = array();
session_register("cart");
$items = 0;
session_register("items");
$totalprice = 0.00;
session_register("totalprice");
$cart = array();
$HTTP_SESSION_VARS['cart'] = array();
$HTTP_SESSION_VARS['items'] = 0;
$HTTP_SESSION_VARS['totalprice'] = 0;
*/
//}
if ($productid){
$pid = $productid;
$productid = "a" . $productid;
$HTTP_SESSION_VARS['cart'][$productid] += $quantity; //assume latest quantity is the correct one
}
?><?php
include ('header.php')
?>
<?php
require("displaycartfunction.php");
?>
<?php
// make connection to database
require("opendbo.php");
?>
<div id="wrap">
<div id="navigation"><script type="text/javascript">
<!--
stm_bm(["menu5df9",820,"","blank.gif",0,"","",1,0,250,0,1000,1,0,0,"","100%",67108955,0,1,2,"default","hand",""],this);
...stm_em();
//-->
</script>
</div>
<div id="content">
<div id="product-container">
<div class="contentDiv" id="welcome"><span class="contentH1"><img src="images/arrow.gif" width="12" height="7" />SHOPPING CART</span><br />
<br />
<table width="750" border="0" align="center">
<p>
<?
displaycart();
?>
<hr>
<?php
/*
// uncomment this section to troubleshoot modifications
echo "<pre>";
echo $pid . "<br>";
echo $productid . "<br>";
echo $query . "<br>";
echo $quantity . "<br>";
print_r($HTTP_SESSION_VARS);
print_r($HTTP_SESSION_VARS['cart']);
echo "</pre>";
*/
?>
<a href="confirmation.php"> Checkout</a>
<a href="gallery.php"> Continue Shopping </a>
</table>
<br />
</div>
</div>
<div class="clear">
</div>
</div>
<?php
include ('footer.html')
?>
Here is the cart function that is required:
<?php
//assumes that opendbo called, and session started when call is made.
function displaycart() {
global $cart, $DBname, $link, $totalprice, $pid, $quantity;
print ("<table cellpadding=\"4px\">");
print ("<tr><td bgcolor=\"#d8d8d8\"><span class=\"item\"> ID </td> <td bgcolor=\"#d8d8d8\"><span class=\"item\"> Photo Name </td><td bgcolor=\"#d8d8d8\"><span class=\"item\"> Quantity </td> <td bgcolor=\"#d8d8d8\"><span class=\"item\"> Total Cost </td> </tr>");
//$items = 0; //note session variable items not used
//$totalprice = 0.00;
//extract($cart);
if ($cart) {
foreach ($cart as $key => $value) {
$items += $value;
$product_id = substr($key, 1);
$query="SELECT * FROM catalog WHERE id=$product_id";
$result = mysql_db_query($DBname, $query, $link);
$item_price = mysql_result($result,0,"cost");
$item_name = mysql_result($result,0,"p_name");
$item_total_price = $item_price * $value;
$totalprice += $item_total_price;
$item_total_pricef = number_format($item_total_price,2);
print ("<tr><td> #$product_id </td> <td> $item_name</td><td> $value </td><td> \$$item_total_pricef </td> </td> ");
}
} else {
//$items += $quantity;
//$pid = $HTTP_GET_VARS['productid'];
//$product_id = substr($productid, 1);
$query=sprintf("SELECT * FROM catalog WHERE id='%s'",$pid);
$result = mysql_db_query($DBname, $query, $link);
$item_price = mysql_result($result,0,"cost");
$item_name = mysql_result($result,0,"p_name");
$item_total_price = $item_price * $quantity;
$totalprice += $item_total_price;
$item_total_pricef = number_format($item_total_price,2);
print ("<tr><td> <b>$pid</b> </td> <td> $item_name </td><td> $quantity </td><td> \$$item_total_pricef </td> </td> ");
}
$totalpricef = "$" . number_format($totalprice,2);
print("<tr> <td> <span class=\"item\">TOTAL </td> <td> </td> <td><span class=\"item\"> $items items</td><td><span class=\"item\"> $totalpricef </td></tr> </table>");
}
?>