I have the following table that fetches data from the database:
while($row = mysql_fetch_array($result))
{
echo '
<tr>
<td width="320">
<input type="checkbox" name="product_ID[]" value="'.$row['Product_ID'].'" />'.$row['Product_description'].'<br />
</td>
<td width="50">
<input type="text" name="product_cost[]" value="'.$row['Product_Retail_cost'].'" maxlength="3" size="3" />
</td>
<td width="50">
<input type="text" name="product_quantity[]" value="1" maxlength="3" size="1" />
</td>
</tr>';
}
What I would like to do, is insert the row into a table, making sure to insert any updated values from the two text boxes. The insert looks like this:
$product_ID = $_POST['product_ID'];
$product_cost = $_POST['product_cost'];
$product_quantity = $_POST['product_quantity'];
for ($i=0; $i<sizeof($product_ID);$i++)
{
$query="INSERT INTO mjj_ordered_products
(`Order_ID`,
`Product_ID`,
`Product_Quantity`,
`Product_Price`)
VALUES ((SELECT MAX(Order_ID) AS Order_ID FROM `mjj_orders`),
'".$product_ID[$i]."',
'".$product_quantity[$i]."',
'".$product_cost[$i]."')";
mysql_query($query) or die (mysql_error());
}
But while this inserts the correct Product_ID, the remaining two values inserted do not correspond to the selected checkbox, but rather by looping through the entire list.
The question: how do I insert the other 2 values associated to the checkbox into the databse?