Here's the scenario. I have products. Products can come in sizes. Sizes are in their own table and are associated with products. So, one product might come in Small, Medium, Large; another might come in X-Small and Medium only.
People can buy multiple of any size of a product. So, the product page displays the product and then all the sizes. Next to each size is a text box, and they can enter in how many they want of each.
The code for this part of the page says:
# Get all the sizes
$sql_size = "
SELECT
s.size_id ,
s.size ,
s.size_order
FROM
size s ,
product2size p2s
WHERE
p2s.product_id = $row_product[product_id] AND
p2s.size_id = s.size_id AND
s.size_active = 1
ORDER BY
s.size_order";
if ($res_size = mysql_query($sql_size)) {
while ($row_size = mysql_fetch_array($res_size)) { ?>
<input type="text" name="sizes[<?=$row_size['size_id'];?>]" size="2"> <?=$row_size['size'];?>
The idea is to put the size and the quantity into an array so that I then can unpack the array and record how many of each size is being ordered.
Once submitted, my code goes on to say:
foreach ($HTTP_POST_VARS['sizes'] as $size => $quantity) {
if ($quantity > 0) {
$sql_add = "
INSERT INTO product2order (
product_id ,
order_id ,
size_id ,
quantity ,
price
) VALUES (
'$HTTP_POST_VARS[product_id]' ,
'$oid' ,
'$size' ,
'$quantity' ,
'$HTTP_POST_VARS[product_price]'
)";
I swear this worked this morning. I was getting a shopping cart with 25 smalls, 15 mediums, etc. Now, it's only posting the first one it sees.
What am I doing wrong here?