I have confusion in inserting multiple records in one row using single checkbox with php mysql
This is my form table
<form action="tambahMatkul.php" method="post" id="ambil_matkul">
<table class="tabel table-bordered table-stripped table-responsive">
<tr>
<th width="5%">cek</th>
<th width="19%">Kode</th>
<th width="19%">Mata Kuliah</th>
<th width="19%">W/P</th>
<th width="19%">SKS</th>
<th width="19%">Kelas</th>
</tr>
<?php
include "koneksi.php";
$query = $connect->query("SELECT * FROM matakuliah")or die(mysqli_error($connect));
while($mahasiswa = $query->fetch_array())
{
?>
<tr>
<td> <input type="checkbox" name="cek[]" value="<?php echo $mahasiswa['kodeMatkul'] ?>">
<
</td>
<td><?php echo $mahasiswa['kodeMatkul']; ?></td>
<td><?php echo $mahasiswa['namaMatkul']; ?></td>
<td><?php echo $mahasiswa['pilihan']; ?></td>
<td><?php echo $mahasiswa['sks']; ?></td>
<td><?php echo $mahasiswa['kelas']; ?></td>
</input>
</tr>
<?php } ?>
</table>
<hr/>
<div class="btn-group">
<button class="btn btn-sm btn-success" type="submit"><i class="fa fa-plus"></i> Tambah</button>
</div>
</form>
This is my form action
<?php
$codes = $_POST['cek'];
foreach($codes as $code)
{
$connect = mysqli_connect("localhost","root","","krs");
$query = mysqli_query($connect, "INSERT INTO krs VALUES(NULL, '161402133', '{$code}')");
}
if($query)
echo "Matakuliah sudah ditambahkan.";
i don't know what to do? still beginner . please help me master