Help with adding sizes to cart page
hello everyone,
I've been racking my brain with this...
I'm trying to display the sizes of shirts when added to my cart.
The sizes come from a select menu.
The sizes show up in the cart, but overwrite the last size added.
For example ..
add shirt1 size-small
add shirt2 size-medium
the cart displays...
shirt 1 size-medium
shirt 2 size-medium
Can you please help me so when I add a new item it doesn't overwrite the previous size.
all help is appreciated
my code is as follows....
selection from my product page
Code:
<select name="shirt_size">
<option value="x-small">x-small</option>
<option value="small">small</option>
<option value="medium">medium</option>
<option value="large">large</option>
</select>
code that displays shirt size
PHP Code:
$output[] = '<td>'.$_POST['shirt_size'].'</td>';
function displaying my cart
PHP Code:
function showCart() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
$output[] = '<table>';
// start div
$output[] = '<div id="cart_table">';
//
$output[] = '<tr>';
$output[] = '<td><h4>Product</h4></td>';
$output[] = '<td><h4>Item No.</h4></td>';
$output[] = '<td><h4>Price</h4></td>';
$output[] = '<td><h4>Size</h4></td>';
$output[] = '<td><h4>Quantity</h4></td>';
$output[] = '<td><h4>Price Total</h4></td>';
$output[] = '<td><h4> </h4></td>';
$output[] = '</tr>';
//new row
foreach ($contents as $product_id=>$qty) {
$sql = 'SELECT * FROM products WHERE product_id = '.$product_id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
//
$output[] = '<tr>';
$output[] = '<td><a href="product.php?product_id='.$product_id.'">'.$product_title.'</a></td>';
$output[] = '<td>'.$product_plu.'</td>';
$output[] = '<td>$'.$product_price.'</td>';
//
$output[] = '<td>'.$_POST['shirt_size'].'</td>';
//
$output[] = '<td><input type="text" name="qty'.$product_id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
$output[] = '<td>X $'.($product_price * $qty).'</td>';
$total += $product_price * $qty;
$output[] = '<td><a href="cart.php?action=delete&product_id='.$product_id.'" class="r">Remove</a> </td>';
$output[] = '</tr>';
//end div
$output[] = '</div>';
}
$output[] = '</table>';
$output[] = '<p>Grand total: <strong>$'.$total.'</strong></p>';
$output[] = '<div class="float-right"><button type="submit">Update cart</button>';
$output[] = '</form>';