title: Php Checkbox - making check and uncheck
body: <p>i try to solve a problem. <br /></p>
  
  <p><img src="https://i.stack.imgur.com/5kOD3.png" alt="enter image description here"></p>
  
  <p>and this is my code.</p>
  
  <pre><code>&lt;?php
  
  require 'connectDB.php';
  print&lt;&lt;&lt;_A_
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  _A_;
  $mysql = new mysql();
  $mysql-&gt;connect();
  
  $dbResult = mysql_query("select * from profiles");
  
  
  
  
  
  
  echo "&lt;form action='#' method='post'&gt;";
  
  $dbResult = mysql_query("select * from profiles");
  
  
  while ($info = mysql_fetch_array($dbResult)) {
  
      if ($info['isPremium'] == 0)
          echo "&lt;input type=checkbox name='check2[]' id='check2' value=".$info['id']."&gt;";
      else
          echo "&lt;input type=checkbox name='check1[]' id='check1' value=".$info['id']." checked&gt;";
  
      echo $info['profileName'] . "&lt;br /&gt;";
  }
  
  echo "&lt;p&gt;&lt;input type='submit' name='btnPremium' /&gt;&lt;/p&gt;";
  echo "&lt;/form&gt;";
  </code></pre>
  
  <p>If user click to a checkbox i send db a query in order to make it 1.However, when a user uncheck a checkbox i take this error: <strong>Undefined index: check2 in C:\xampp\htdocs\googleAnalytics\GAPI\choosePremium.php on line 43</strong>  I try to keep unchecks in arrPremium2 :S</p>
  
  <pre><code>if (isset($_POST['btnPremium'])) {
  
      $arrPremium = $_POST['check1'];
      foreach($arrPremium as $result)
      {
          mysql_query("UPDATE profiles set isPremium=1 where id=".$result."");
      }
  
      $arrPremium2 = $_POST['check2'];
      print_r($arrPremium2);
  }
  ?&gt;
  </code></pre>