I would like to know how do I get the value of the checkbox that is assigned by an ID to it at the same time.
Here is my brief code:
<table class="data" cellpadding="0" cellspacing="0">
<?php
$select=mysql_query("select * from products_list ORDER BY id ASC");
while($row=mysql_fetch_array($select)){
$class = ' class="new_arrival" ';
echo "<tr>
<td>".$row['id']."</td>
<input type='hidden' name='product_id' value='".$row['id']."' />
<input type='checkbox' name='product_new' checked='checked' onclick='document.product_listing.submit();' /></td></tr>";
?>
</table>
if (isset($_POST['product_new'])) {
$id = $_POST['product_id'];
echo ("<script language='JavaScript'>
window.alert('".$id."')
</script>");
}
The result I keep getting for ID is the latest record in database but the value of the checkbox works fine.
I've tried this:
<input type='checkbox' name='product_new[".$row['id']."]' checked='checked' onclick='document.product_listing.submit();' />
foreach($_POST['product_category'] as $id => $value)
Using foreach loop, it did work somehow but it will loop through those checkboxes whether it's checked or uncheck.
Hope you guys understand, been stuck in this for 2 days. My purpose is to click the checkbox be it check or uncheck, it will update the database according to the ID which is assigned by mysql show result.
Any help will be much appreciated. Thanks!!
product_new[".$row['id']."]but youforeachover$_POST['product_category']- try looping$_POST['product_new']instead.