title: How to Insert Primary key from checkbox
body: <p>I want to input the data into the table <code>id_ss</code> <code>ss_kat</code> and enter <code>ss_kat</code> <code>id_kat</code> on the table, so the data will be displayed on the input <code>kat</code> <code>ss_kat</code> the checkbox menu, but I have tried repeatedly 2 can not, there are approximately erornya where?</p>
  
  <p><a href="https://i.stack.imgur.com/sLlC7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sLlC7.png" alt="enter image description here"></a></p>
  
  <p>I want to submit the checkbox in table <code>kat</code> and sample index from image here </p>
  
  <pre><code>&lt;?php
      include "../../inc/conn.php";
  ?&gt;
  
  &lt;div class="row"&gt;
  &lt;div class="col-md-6"&gt;
      &lt;form action="proses.php" method="POST" enctype="multipart/form-data" style="margin-top:20px;"&gt;
          &lt;input type="hidden" name="id_ss_kat" /&gt;
  
          &lt;?php
                  $ss = mysql_query("SELECT * from ss");
          ?&gt;
  
          &lt;select class="form-control" name="id_ss"&gt;
          &lt;?php
              while ($rows=mysql_fetch_array($ss)) 
              { ?&gt;
              &lt;option class="form-control" value="&lt;?php echo $rows['id_ss'];?&gt;" name="id_ss"&gt;&lt;?php echo $rows['name'];?&gt;&lt;/option&gt;
  
          &lt;?php
              }
          ?&gt;
          &lt;/select&gt;
          &lt;br&gt;
          &lt;?php
              $kat = mysql_query("SELECT * from kat WHERE kat_status='1'");
          ?&gt;
  
          &lt;?php
              while ($rows=mysql_fetch_array($kat)) 
              { ?&gt;
  
          &lt;input type="checkbox" name="id_kat[&lt;?php echo $rows['id_kat'];?&gt;]" value="&lt;?php echo $rows['id_kat'];?&gt;"&gt;&lt;?php echo $rows['nama'];?&gt;
  
          &lt;?php
              }
          ?&gt;
  
          &lt;br&gt;
          &lt;input class="btn btn-primary" type="submit" name="ssf" value="SAVE"&gt;
          &lt;br&gt;
      &lt;/form&gt; 
      &lt;br&gt;
  
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and here is proses.php</p>
  
  <pre><code>&lt;?php
      if (isset($_POST['ssf'])) {
          $id_ss_kat          = $_POST['id_ss_kat'];
          $id_kat             = $_POST['id_kat'];
          $id_ss              = $_POST['id_ss'];
  
          foreach($id_kat as $kat) {
              $source.=$kat.", ";
          }
          $one=substr($source,0,-1);
  
          $q      = "INSERT into ss_kat VALUES('$id_ss_kat','$one','$id_sekolah')";
          $dq     = mysql_query($q);
  
          if ($dq) {
              echo "berhasil";
          }else{
              mysql_error();
          }
  
      }
  ?&gt;
  </code></pre>
  
  <p>The index look like in the picture below:</p>
  
  <p><a href="https://i.stack.imgur.com/sZPKZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sZPKZ.png" alt="enter image description here"></a></p>