Hi,
I’m trying to update in insert into the ‘menu’ column of my database with the word ‘single’ if the checkbox is ticked and in the Form below but unfortunately it’s not updating it for me and is setting all the values in the ‘menu’ column on the database to 0.
I have a few multiple checkboxes in this form and I just wanted to be able to update the database as per what the user ticks however as I’ve seen over a few searches on the net that the checkbox is like a button and doesn’t hold a value unless it’s ticked so it’s throwing all sorts of errors such as undefined index to name but a few.
I’m quite new to all this and just can’t seem to figure out how to get around this. I have been at this since December and just can’t get my head around what’s missing. What I should point out is that if I change type="checkbox" to type="text" the from works a treat however I need to use checkboxes as letting the user input the word ‘single into the form is obviously a very risky method.
Can anyone help me to figure out what I’m missing?
Thanks very much
for($i=0; $i < $totalRows_GetMenuUpdate; $i++) {
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
if($_POST["menu_bf"][$i] == ""){ $_POST["menu_bf"][$i] = 0;}
$updateSQL = sprintf("UPDATE tbl_prdt
SET menu='%s'
WHERE cate_ID='%s'",
$_POST['menu_bf'][$i],
$_POST['id_bf'][$i]);
mysql_select_db($database_, $);
$Result1 = mysql_query($updateSQL, $) or die(mysql_error());}
?>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td><strong> title:</strong></td>
<td><strong> Tick</strong></td>
</tr>
<?php do { ?>
<tr valign="baseline">
<td><?php echo $row_GetMenuUpdate['category_Name']; ?></td>
<td>
<!-- if I use this to physically add the details it works so I know that the database query is working<input name="menu_bf[]" type="text" value="<?php //echo $row_GetMenuUpdate['menu']; ?>" size="3">-->
<input type="checkbox" name="menu_bf[]"
value="<?php echo $row_GetMenuUpdate['menu']; ?>"
<?php if($row_GetMenuUpdate['menu'] == 'single'){
echo "checked=\"checked\"" .'/>'.'</td>'.'</tr>'; ?>
<?PHP } else {
echo '/>'.'</td>'.'</tr>';
} // End
?>
</td>
</tr>
<input type="hidden" name="id_bf[]" value="<?php echo $row_GetMenuUpdate['category_ID']; ?>">
<?php } while ($row_GetMenuUpdate = mysql_fetch_assoc($GetMenuUpdate)); ?>
<tr valign="baseline">
<td><input type="submit" value="Update record"></td>
<td> </td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
</form>