php shopping cart without php

So i have this shopping cart program i need to build, but without sql below is the code i have…Can someone either help fix the code or help me do it the right way.

i need to output the quanitity and itemID that is all

[php]

  <p>A09_DictCart/default.htm</p>
  <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&amp;itemID=007228&amp;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&amp;itemID=007420&amp;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&amp;itemID=07741&amp;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&amp;itemID=010315&amp;quantity=1">Add 
        this to my cart!</a>
      </TD>
    </TR>
  </TBODY>
</TABLE>

  <p><a href="viewCart.php">View Cart</a></p>
  
  <p>&nbsp;</p>

[/php]

[php]

<?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; } ?> View Shopping Cart [/php]

[php]

<?php session_start(); echo "

" .'Shopping Cart Contents'."

"; if(isset($_SESSION['cart'])){ echo ""; foreach ($_SESSION['cart'] as $cart){ echo ""; } echo "</table"; } else{ echo "

No items in cart.

"; } ?> New Page 1

Back to Catalog

[/php]

Item ID Quantity
". $_SESSION['cart'][$itemID]." ". $quantity."

Try something like this

[php]echo “

”;
foreach ($_SESSION[‘cart’] as $item => $quantity){
echo “"; // shouldn’t this line also start with a tr?
}[/php]

btw: you shouldn’t use tables for layout

Item ID Quantity
”. item ." ". $quantity."

so how would you do it. I am trying to find the best way to get all this to work. I mean am I doing the sessions right in the previous part? I am having a hard time with this whole thing.

try not to get frustrated, it’s not exactly the easiest stuff to jump into. He is talking about layout now not php, and you would want to use divs to set up your layout instead of tables. google divs instead of tables or something similar and you will have more information than you need.

So I got the php to output the stuff i need…but now i cant get the item quantity to remove just one if they click remove. The query string stuff is confusing me horribly. Do it needs to go back to updateCart.php to remove but after that im stuck. I think i can figure out the empty cart feature from there.

Feel free to let me know if the update cart isnt right as well. Sessions are a little rough with me too.

The code i have is below pleaseeeeeeeeeeee helpppp lol

Thanks to all

viewCart.php
[php]

<?php session_start(); echo "

" .'Shopping Cart Contents'."

"; if(isset($_SESSION['cart'])){ echo ""; foreach ($_SESSION['cart'] as $item => $quantity){ echo ""; } echo "
Item ID Quantity
". $item ." ". $quantity." Remove
"; } else{ echo "

No items in cart.

"; } ?> View Cart

Back to Catalog

[/php]

updateCart.php

[php]

<?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; } ?> View Shopping Cart [/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service