I am trying to create a shopping cart with sessions. I want the final session to end up as something like 'number,number,numer' with the numbers being various product ids. I have the following codes on the pages but the view-cart.php page shows nothing.
product.php
PHP Code:
echo("<form action=\"add-cart.php\" method=\"post\">\n");
echo("<input type=\"hidden\" name=\"id\" value=\"".$id."\">\n");
echo("<input type=\"submit\" value=\"Add to Cart\">\n");
echo("</form>\n");
add-cart.php
PHP Code:
$prodid = $_POST['id'];
$cart = $_SESSION['cart'];
if ($cart) {
$_SESSION['cart'] .= ",".$prodid;
} else {
session_register('cart');
$_SESSION['cart'] == $prodid;
}
view-cart.php
PHP Code:
echo($_SESSION['cart']);
session_start(); is included as default at the very top of all pages.
The problem is the code on view-cart.php echoes nothing
please help!