I am trying to create a third column in my simple shopping cart that will delete the item from the cart. I tried the line below to achieve this feature:
echo "<td><a href=" . $_SERVER['PHP_SELF'] . "?delete=" .$n. ">Delete</a></td>";
It seems to word with some bugs it will not remove "delete=0"
and it will sometime remove an item but not it's price it will leave 0.00
I thought this would be a easy question to answer any thoughs?? why I am getting this strange errors??
http://www.nucitytech.com/store.php
here is the enter script below:
<?PHP
session_start();
if(!isset($_SESSION['cart'])){
$_SESSION['cart']=array();
}
if(!empty($_GET['delete'])){
unset( $_SESSION['cart'][$_GET['delete']] ) ;
}
$products=array('IBM Laptop', 'Dell Laptop', 'Gateway Desktop', 'Service Contract');
$prices=array(200.00, 300.00, 400.00, 199.99);
echo "<table cellspacing=20 >";
echo "<tr><th>Item Title</th><TH>Price</th></tr>";
for($n=0;$n<count($_SESSION['cart']);$n++){
echo "<tr>";
echo "<td>".$products[$_SESSION['cart'][$n]]."</td>";
echo "<td>".number_format($prices[$_SESSION['cart'][$n]],2)."</td>";
echo "<td><a href=" . $_SERVER['PHP_SELF'] . "?delete=" .$n. ">Delete</a></td>";
echo "</tr>";
$total = $total + $prices[$_SESSION['cart'][$n]];
}
echo "<td><b>TOTAL</td></b>";
echo "<td>".number_format($total,2)."</td>";
echo "<td><a href=store.php>Continue Shopping</a></td>";
echo "</table>";
?>