i am creating a shopping cart application but there is a problem while testing $_Session['cart'][$product_ID] its is not setting the values according to the $action variable that i called from a url query from a previous page when I activate query for any of the actions the corresponding switch statement is not making any sort of change to Session variable. code is listed below
session_start();
include "db-class.php";
include "functions.php";
$product_ID=$_GET["id"];
$action=$_GET["action"];
$_SESSIONS['cart'][$product_ID]=0;
/////////// testing session variable and action at start/////////
echo "<br>SESSION VAR BEFORE ACTION=".$_SESSIONS['cart'][$product_ID];
echo "<br>ACTION TO TAKE= ".$action."<br>";
//////////end initial testing/////////
$productExisits=productExists($product_ID);
if($product_ID && !$productExisits)
{
die("PRODUCT DOESNOT EXIST");
}
switch($action)
{
case "add":
$_SESSION['cart'][$product_ID]++;
break;
case "remove":
if($_SESSION['cart'][$product_ID]>0)
{
$_SESSION['cart'][$product_ID]--;
}
if($_SESSION['cart'][$product_ID]=0)
{
unset($_SESSION['cart'][$product_ID]);
}
break;
case "empty":
unset($_SESSION['cart'][$product_ID]);
break;
}
/////////////// testing session variable after action/////////
if(!isset($_SESSION['cart'][$product_ID]))
{
echo "<br>THE CART IS EMPTY NOW<br>";
}
echo "SESSION ID IS= ".$_SESSIONS['cart'][$product_ID];
?>
However i want it to change the variable values every time when i perform certain action
idex.html is
<?php
//session_start();
?>
<html>
<head>
</head>
<body>
<div>
<image src="img/b_guitar.jpg" height="100 px" width="270 px" border= "2 px">
<table>
<tr>
<td>
<a href="cart.php?action=add&id=1">add to cart</a> ||<br>
<td>
<a href="cart.php?action=remove&id=1">remove from cart</a> ||<br>
<td>
<a href="cart.php?action=empty&id=1">empty cart</a><br>
</tr>
</table>
</div>
</body>
</html>