title: PHP how to save checkbox value in database?
body: <p>I have table with checkboxes, which I retrieve from database :</p>
  
  <pre><code>&lt;?php
  $result = mysql_query("SELECT shop_id, name FROM shop") or die(mysql_error());
  
  if(mysql_num_rows($result) &gt; 0)
  {
      while($row = mysql_fetch_assoc($result)) 
      {
          echo '&lt;tr&gt; 
                    &lt;td&gt;
                        &lt;input type="checkbox" name="identifer[]" value="'.$row['shop_id'].'" /&gt; &lt;br /&gt;
                    &lt;/td&gt;  
                    &lt;td&gt;'.ucfirst($row['shop']).'&lt;/td&gt; 
                &lt;/tr&gt;   ';    
       }
  }
  ?&gt;
  </code></pre>
  
  <p>I want to save the results in database:</p>
  
  <ul>
  <li>Table: <code>places</code></li>
  <li>Columns: <code>places_id</code>, <code>book_id</code>, <code>shop_id</code></li>
  </ul>
  
  <p>However, I can't get it to work right. In <code>shop_id</code> column I get the same number as many times as checkboxes are checked.</p>
  
  <p>If I'm using this:</p>
  
  <pre><code>$identifer = $_POST['identifer'];
  if( count( $identifer) &gt; 1)
  {
      foreach($identifer as $x)
      {
          $y .= $x.",";
          $val = rtrim($y,",");
          $q2 = "INSERT INTO places (places_id, book_id, shop_id) VALUES (NULL, '$book_id', '$val')";
          $result2 = mysql_query($q2) or die(mysql_query());
      }
  }
  </code></pre>
  
  <p>In <code>places</code> table I get just one row no matter how many times checkboxes are checked.</p>
  
  <p>So what is the correct way to do that?</p>