I have a form selection that allows users to select a product from a dynamically generated MySQL list and then rate the product using radio buttons.
<input type="checkbox" value="$row[ProdID]" name="Product[]" id="Product$row[ProdID]" onclick="showhide_div($row[ProdID])" />$row[ProductName]
<div id="div$row[CatID]" style="display:none">
<input type="radio" name="ProductQual$row[ProdID]" id="PQ$row[ProdID]" value="1" /> Poor
<input type="radio" name="ProductQual$row[ProdID]" id="PQ$row[ProdID]" value="2" /> Fair
<input type="radio" name="ProductQual$row[ProdID]" id="PQ$row[ProdID]" value="3" /> Good
<input type="radio" name="ProductQual$row[ProdID]" id="PQ$row[ProdID]" value="4" /> Excellent
</div>
I want to put the selected radio value for each of the “checked” products into a MySQL table
-----------------
| ProdID(a) | 3 |
| ProdID(b) | 1 |
-----------------
I know I need to for_each each selected Product but I am having trouble figuring out how to related the correct radio button from the overall $POST to the Product during the for_each loop to put the values into the MySQL table.
There may be a more elegant way of doing things, but this would be my solution. I wrapped your checkboxes and radios in
<label></label>tags, so the text is clickable (a good accessibility guideline to practice, too). RADIOs are generated with a unique ID for each product.And on the back-end, all ratings fields are parsed and inserted into a table.