title: Using Checkboxes to Update a MySql Database
body: <p>Ok, I know I'll probably get bashed for even asking this... its been about 5-6 years since I've touched PHP and MySql, so I think I may be overthinking all of this.</p>
  
  <p>I have an HTML form, that is a series of checkboxes, and by clicking one, I would like it to set it's relative entry in the database to 0 or 1. When the update is complete, it returns to the form so I can change the settings again if needed.</p>
  
  <p>The amount of entries (checkboxes) will be a static amount will be static, so I don't think a foreach loop will be necessary, I'm more or less trying to jog my memory on how to work with PHP, and I'm not having much luck reading a whole mess of answers scattered about SO that kinda have to deal with what I'm trying to do.</p>
  
  <p>Any help will be greatly appreciated.</p>
  
  <p><strong>FORM:</strong></p>
  
  <pre><code>&lt;?php
  
   require "config.php";
  
   $db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
   mysql_select_db($db_name) or die(mysql_error());
  
   $query = "SELECT * FROM roster";
   $result = mysql_query($query);
  
  ?&gt;
  &lt;form action="update.php"  method="POST"&gt;
  &lt;?php
  
          while( $row = mysql_fetch_array($result) ){
              $active = $row['active'];
              $name = $row['name'];
              $class = $row['class'];
              $value = '0';
  
              if ($active == '1'){
                  $value = '0';
              } else {
                  $value = '1';
              }
  
              echo "&lt;label class='switch'&gt;&lt;input type='checkbox' name='".$class."' value='". $value."'";
  
              if($active == '1'){
                  echo "checked='checked'";
              }
  
              echo "/&gt;&lt;div class='slider'&gt;&lt;/div&gt;&lt;span&gt;" . $name . "&lt;/span&gt;&lt;/label&gt;";
          }
  
   mysql_close();
   ?&gt;
  &lt;input type="submit" class="submit" value="Update Active Roster"&gt;
  &lt;/form&gt; 
  </code></pre>
  
  <p><strong>Update.php (so far) - this is where I need help, I think</strong></p>
  
  <pre><code>&lt;?php
  require "config.php";
  
  $db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
  mysql_select_db($db_name) or die(mysql_error());
  
  $checkbox = $_POST['activate'];
  for($i = 1; $i &lt; sizeof($checkbox)+1; $i++){
      $query = "UPDATE roster SET active='".$checkbox[$i]."' WHERE id='".$i."'";
      echo "active='".$checkbox[$i]."' WHERE id='".$i."'";
      mysql_query($query) or die(mysql_error());
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>MySQL Database</strong></p>
  
  <pre><code>id   class      name         active
  0    thisdude   This Dude    0
  1    thatguy    That Guy     0
  2    somechick  Some Chick   0
  </code></pre>