It shouldnt be that difficult but what I have does not work
Can someone help me figure out where I am going wrong?
PS- I only need to display 2 things in the cart the quantity and itemID
<?php?> <HTML> <HEAD> </HEAD> <BODY> <p>A09_DictCart/default.htm</p> <center> <h2>Catalog</h2> <TABLE border=1 cellPadding=3 cellSpacing=1> <TBODY> <TR> <TD>Image</TD> <TD>ItemID</TD> <TD>Description</TD> <TD>Price</TD> <TD>Add Item To Cart</TD></TR> <TR> <TD><IMG src="./images/p007228iiob.jpg" width="100" height="100"></TD> <TD>007228</TD> <TD>Dri-Plus Dri-Fowl Wading Jacket</TD> <TD>$99.95</TD> <TD><a href="updateCart.php?action=add&itemID=007228&quantity=1">Add this to my cart!</a></TD></TR> <TR> <TD><IMG src="./images/p007420iiob.jpg" width="100" height="100"></TD> <TD>007420</TD> <TD>Scent-Lok Blaze Over Jacket</TD> <TD>$69.95</TD> <TD><a href="updateCart.php?action=add&itemID=007420&quantity=1">Add this to my cart!</a></TD></TR> <tr> <TD><IMG src="./images/p007741ii01.jpg" width="100" height="100"></TD> <TD>07741</TD> <TD>Switchback Boot</TD> <TD>$119.95</TD> <TD><a href="updateCart.php?action=add&itemID=07741&quantity=1">Add this to my cart!</a></TD> </tr> <TR> <TD><IMG src="./images/p010315iiob.jpg" width="100" height="100"></TD> <TD>010315</TD> <TD>Master Guide Wading Boot</TD> <TD>$64.95</TD> <TD><a href="updateCart.php?action=add&itemID=010315&quantity=1">Add this to my cart!</a> </TD> </TR> </TBODY> </TABLE> <p><a href="viewCart.php">View Cart</a></p> <p> </p> </center> </BODY> </HTML>
<?php session_start(); if(isset($_GET['itemID'])) { $itemID = $_GET['itemID']; } else { $itemID = 1; } if(isset($_GET['action'])) { $action = $_GET['action']; } else { $action = "empty"; } switch ($action) { case "add": if(isset($_SESSION['cart'][$itemID])){ $_SESSION['cart'][$itemID]++; } else{ $_SESSION['cart'][$itemID]=1; } break; case "remove": if(isset($_SESSION['cart'][$itemID])){ $_SESSION['cart'][$itemID]--; if(isset($_SESSION['cart'][$itemID])==0){ unset($_SESSION['cart'][$itemID]); } } break; case "empty": unset($_SESSION['cart']); break; } ?> <html> <head></head> <body> <a href="viewCart.php">View Shopping Cart</a> </body> </html>
<?php session_start(); echo "<h2>" .'Shopping Cart Contents'."</h2>"; if(isset($_SESSION['cart'])){ echo "<table><tr><th>Item ID</th><th>Quantity</th></tr>"; foreach ($_SESSION['cart'] as $cart){ echo "<td>". $itemID ."</td><td>". $quantity."</td></tr>"; } echo "</table"; } else{ echo "<h2>No items in cart.</h2>"; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>New Page 1</title> </head> <body> <center> <p align="center"><a href="index.php">Back to Catalog</a></p> </center> </body>