title: mysqli insert into database from multiple checkbox with foreach
body: <p>so i tried to get data from my database to checkbox and this is what i have tried :</p>
  
  <pre><code>&lt;?php
  $query = "SELECT * FROM siswa WHERE id_tingkatan='$idtingkatan'";
  $result = $koneksi-&gt;query($query);
  while($row=$result-&gt;fetch_assoc()){
  ?&gt;
  &lt;input type="checkbox" name="murid[]" value="&lt;?php echo $row['id_siswa']; ? &gt;"&gt;&lt;?php echo $row["nama_siswa"]; ?&gt;&lt;br&gt;&lt;br&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>and save the value of checked checkbox into database, this is what i have tried :</p>
  
  <pre><code>if(isset($_POST["submit"]))
  {
  if(!empty ($_POST['murid']))
    {
      $i= 0;
      foreach($_POST as $murid){  
      $kelas = $_POST['kelas'];
      $murid = $_POST['murid'][$i];
      $query = "INSERT INTO murid (id_kelas, id_siswa) VALUES ('$kelas', '$murid')";
      $q = mysqli_query($koneksi, $query) or die (mysqli_error($koneksi));
      $i++;
      }
      }
      else
      {
      echo "&lt;script type= 'text/javascript'&gt;alert('Pilih minimal 1 siswa');&lt;/script&gt;";
      header('Location: ./kelas.php');
      }
    }
  </code></pre>
  
  <p>when i submit it does input to database but theres one extra row with id_siswa value as 0</p>