I have a shopping cart with a foreach() to update the quantities.
HTML
<form method="post" >
<?php while ($data2 = mysql_fetch_array( $data)) { ?>
<tr>
<td> <input name="quantity" type="text" class="form-field" size="3" value="<? echo $data2['quantity'];?>" />
<input type="hidden" name="product_id" value="<? echo $data2['product_id']; ?>">
</td>
</tr>
<? } ?>
</form>
AND FOR MY PHP, I have
if (isset($_POST['submit_qty']))
{
foreach($_POST['product_id'] as $key => $id)
{
$item_id = $id;
$quantity = $_POST['quantity'][$key];
$sql2 = "update cart SET quantity = '".$quantity."' where product_id = '".$item_id."' ";
$result2 = mysql_query($sql2) or die ("Error in query: $result2");
}
header('Location: mycart.php');
exit();
}
IF I Echo my sql query I get :
Warning: Invalid argument supplied for foreach()
what could be the problem ?