Updating multiple Checkboxes

  • Addos
  • Novice
  • Novice
  • Addos
  • Posts: 21

Post 3+ Months Ago

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

Code: [ Select ]
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>&nbsp;</td>
      </tr>
    </table>
<input type="hidden" name="MM_update" value="form1">
  </form>
  1. for($i=0; $i < $totalRows_GetMenuUpdate; $i++) {
  2. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  3. if($_POST["menu_bf"][$i] == ""){ $_POST["menu_bf"][$i] = 0;}
  4.       $updateSQL = sprintf("UPDATE tbl_prdt
  5.        SET menu='%s'
  6.        WHERE cate_ID='%s'",
  7.        $_POST['menu_bf'][$i],
  8.        $_POST['id_bf'][$i]);
  9.    
  10.   mysql_select_db($database_, $);
  11.   $Result1 = mysql_query($updateSQL, $) or die(mysql_error());}
  12. ?>
  13.  
  14. <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  15.     <table align="center">
  16.    
  17.       <tr valign="baseline">
  18.         <td><strong> title:</strong></td>
  19.         <td><strong> Tick</strong></td>
  20.       </tr>
  21.         <?php do { ?>
  22.       <tr valign="baseline">
  23.         <td><?php echo $row_GetMenuUpdate['category_Name']; ?></td>
  24.         <td>
  25.  
  26.         <!-- 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">-->
  27.  
  28.     <input type="checkbox" name="menu_bf[]"
  29.   value="<?php echo $row_GetMenuUpdate['menu']; ?>"
  30.    <?php  if($row_GetMenuUpdate['menu'] == 'single'){
  31.  echo "checked=\"checked\"" .'/>'.'</td>'.'</tr>'; ?>
  32.           <?PHP } else {
  33.         echo  '/>'.'</td>'.'</tr>';
  34.         } // End
  35.         ?>      
  36.            
  37.         </td>
  38.       </tr>
  39.          
  40.     <input type="hidden" name="id_bf[]" value="<?php echo $row_GetMenuUpdate['category_ID']; ?>">
  41.       <?php } while ($row_GetMenuUpdate = mysql_fetch_assoc($GetMenuUpdate)); ?>
  42.       <tr valign="baseline">
  43.         <td><input type="submit" value="Update record"></td>
  44.         <td>&nbsp;</td>
  45.       </tr>
  46.     </table>
  47. <input type="hidden" name="MM_update" value="form1">
  48.   </form>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 105 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.