Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert all the values in a row based on a selected checkbox
    text
    copied!<p>I have the following table that fetches data from the database:</p> <pre><code>while($row = mysql_fetch_array($result)) { echo ' &lt;tr&gt; &lt;td width="320"&gt; &lt;input type="checkbox" name="product_ID[]" value="'.$row['Product_ID'].'" /&gt;'.$row['Product_description'].'&lt;br /&gt; &lt;/td&gt; &lt;td width="50"&gt; &lt;input type="text" name="product_cost[]" value="'.$row['Product_Retail_cost'].'" maxlength="3" size="3" /&gt; &lt;/td&gt; &lt;td width="50"&gt; &lt;input type="text" name="product_quantity[]" value="1" maxlength="3" size="1" /&gt; &lt;/td&gt; &lt;/tr&gt;'; } </code></pre> <p>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:</p> <pre><code>$product_ID = $_POST['product_ID']; $product_cost = $_POST['product_cost']; $product_quantity = $_POST['product_quantity']; for ($i=0; $i&lt;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()); } </code></pre> <p>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.</p> <p>The question: how do I insert the other 2 values associated to the checkbox into the databse?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload