You have just made me realize the problem probably isn't with my view_cart code but the code that passes the information to it; add_cart. The 39 is actually the product_id for that product I added. However something with my add_cart must not be working because it is not passing any more than one product_id.
I have never made a cart before and am confused as to where I am going wrong. I'm not sure if there is anything obvious, but if there is please let me know. Otherwise I'm just going to keep on trucking and hope I can find the problem somewhere. Man coding can be tricky! hehe
Here is the code (add_cart) that adds the product to the pior code (view cart), must be a logic error somewhere...:
<?php # Script 13.8 - add_cart.php
// This page adds prints to the shopping cart.
if (is_numeric ($_GET['$pid'])) { // Check for a product ID.
$pid = $_GET['product_id'];
// Set the page title and include the HTML header.
$page_title = 'Add to Cart';
include_once ('header.html');
// Check if the cart already contains one of these prints.
if (isset ($_SESSION['cart'][$pid])) {
$qty = $_SESSION['cart'][$pid] + 1;
} else {
$qty = 1;
}
// Add to the cart session variable.
$_SESSION['cart'][$pid] = $qty;
// Display a message.
echo '<p>The print has been added to your shopping cart.</p>';
include_once ('footer.html'); // Require the HTML footer.
} else { // Redirect
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
exit();
}
?>
The first part of my if statement is returning true, the code prints "the print has been added to your shopping cart." after execution. So maybe I'm wrong and this isn't where my problem is coming from... hmmm....