title: Undefined Index in Checkbox
body: <pre><code>&lt;form method=&quot;POST&quot; action=&quot;&lt;?php $_SERVER['PHP_SELF']; ?&gt;&quot;&gt;
      &lt;table border=&quot;1&quot; cellpadding=&quot;4&quot;&gt;
          &lt;tr&gt;
              &lt;th&gt;Id&lt;/th&gt;
              &lt;th&gt;Name&lt;/th&gt;
  
          &lt;/tr&gt;
          &lt;?php
          include('connect.php');
          $getQuery = &quot;SELECT id,username,admin FROM tutorial_users ORDER BY id ASC&quot;;
          $getResult = mysql_query($getQuery) or die(&quot;Query not executed&quot;);
          while (list($id, $userName, $admin) = mysql_fetch_row($getResult)) {
              ?&gt;
              &lt;?php
              $checked = ($admin == 1) ? 'checked=&quot;checked&quot;' : '';
              ?&gt;
              &lt;tr align=&quot;center&quot;&gt;
                  &lt;td&gt;&lt;?php echo $id; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $userName; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo &quot;&lt;input type='checkbox' name='admin[]' value='$id' $checked&gt;&quot;; ?&gt;&lt;/td&gt;
              &lt;?php } ?&gt;
          &lt;tr&gt;
      &lt;/table&gt;
      &lt;p&gt;
          &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Update Role&quot;&gt;
      &lt;/p&gt;
  &lt;/form&gt;
  &lt;?php
  $updated = FALSE;
  if (isset($_POST['submit'])) {
      $admin = $_POST['admin'];
      $admin = join(&quot;,&quot;, $admin);
      $admin = &quot;(&quot; . $admin . &quot;)&quot;;
      $defaultQuery = &quot;UPDATE tutorial_users SET admin=0&quot;;
      $defaultResult = mysql_query($defaultQuery);
      $upQuery = &quot;UPDATE tutorial_users SET admin=1 WHERE id IN $admin&quot;;
      echo $upQuery;
      $upResult = mysql_query($upQuery);
      $updated = TRUE;
  }
  ?&gt;
  </code></pre>
  <p>In the above code I have 2 questions:</p>
  <ol>
  <li><p>Lets say I want every check box to be unchecked and then when I press the submit, it gives me <code>undefined index $admin</code>, how can I fix this?</p>
  <p>It is working fine when I'm checking at least one box and it passes the value to the POST array.</p>
  </li>
  <li><p>Secondly I would like to know that is this a good approach to achieve result or we can have some other way? Personally I'm feeling it bad because if I have 1000 record then it will take a lot of time to update 2 queries one by one.</p>
  </li>
  </ol>
  <p>Result: What I want is pretty simple that the checked box should have value = 1 where as unchecked have 0.</p>