Hi everyone,
I'm trying to create a shopping-cart esque style system and I'm having a bit of trouble.
Currently I have the shopping cart displaying the sku and the quantity associated with that sku. I have it adding the values so if you go back and add the same item to your cart again, it updates the quantity from 1 to 2, not just adding another entry.
However, now I want it to display the price associated with that item and I'm getting a little confused. Currently, whenever I add something to the cart, it updates ALL the prices in the cart to the price of the newly added item.
For example: if I have one ipod sock in there for 12.00 and then add ipod headphones for 30.00, it says "1 ipod sock 30.00, 1 ipod headphones 30.00" I dont know what I'm doing wrong. I included the code below.
Current Order:<br>
<?
if(isset($_GET['submittedFormTest'])){
$sku= $_GET['sku'];
$quantity = $_GET['quantity'];
$price=$_GET['price'];
$_SESSION[$sku] = $_SESSION[$sku] + $quantity;
?>
<table border=1>
<tr><td>Quantity</td><td>sku</td><td>Description</td><td>Price Each</td><td>Total</td><tr>
<?
foreach($_SESSION as $key=>$value){
echo "<tr><td>$key</td><td>$value</td><td></td><td>$price</td><td></td></tr> <br />";
}
}
?>
I've tried adding a variable $SESSION[$price] but then the foreach explodes that SESSION variable and I can't figure out how to make that for each statement only apply to the $SESSION[$sku];