title: Inserting checkbox values into database
body: <p>I have a form with several checkboxes which values are pulled from a database.
  I managed to display them in the form, assign an appropriate value to each, but cannot insert their values into other database.</p>
  <p>Here's the code:</p>
  <pre><code>&lt;form id=&quot;form1&quot; name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;&gt;
  &lt;?php
  $info_id = $_GET['info_id'];
  $kv_dodatoci = mysql_query(&quot;SELECT * FROM `dodatoci`&quot;) or die('ERROR DISPLAYING: ' . mysql_error());
  while ($kol = mysql_fetch_array($kv_dodatoci)){
      $id_dodatoci = $kol['id_dodatoci'];
      $mk = $kol['mk'];
  
  
      echo '&lt;input type=&quot;checkbox&quot; name=&quot;id_dodatoci[]&quot; id=&quot;id_dodatoci&quot; value=&quot;' . $id_dodatoci . '&quot; /&gt;';
      echo '&lt;label for=&quot;' . $id_dodatoci.'&quot;&gt;' . $mk . '&lt;/label&gt;&lt;br /&gt;';
    }
  ?&gt;
  &lt;input type=&quot;hidden&quot; value=&quot;&lt;?=$info_id?&gt;&quot; name=&quot;info_id&quot; /&gt;
  &lt;input name=&quot;insert_info&quot; type=&quot;submit&quot; value=&quot;Insert Additional info&quot; /&gt;
  &lt;/form&gt;
  &lt;?php
  if (isset($_POST['insert_info']) &amp;&amp; is_array($id_dodatoci)) {
      echo $id_dodatoci . '&lt;br /&gt;';
      echo $mk . '&lt;br /&gt;';
  
      // --- Guess here's the problem  ----- //
      foreach ($_POST['id_dodatoci'] as $dodatok) {
           $dodatok_kv = mysql_query(&quot;INSERT INTO `dodatoci_hotel` (id_dodatoci, info_id) VALUES ('$dodatok', '$info_id')&quot;) or die('ERROR INSERTING: '.mysql_error());
       }
  }
  </code></pre>
  <p>My problem is to loop through all checkboxes, and for each checked, populate a separate record in a database.
  Actually I don't know how to recognize the which box is checked, and put the appropriate value in db.</p>