<td>
<input type="number" name="qty_masuk[]" id="qty_masuk" class="form-control" placeholder="QTY">
</td>
<td>
<div class="form-control">
<input type="checkbox" id="id_barang" name="id_barang[]" value="<?php echo $st['id_barang']; ?>">
</div>
</td>
code html view
public function add_selected_barang()
{
if (isset($_POST['submit'])) {
$id_barang = $_POST['id_barang'];
$qty_masuk = $_POST['qty_masuk'];
for ($i = 0; $i < count($id_barang); $i++) {
if ($qty_masuk != NULL) {
$category_id = $id_barang[$i];
$category_qty = $qty_masuk[$i];
$this->Po_model->multisave($category_id, $category_qty);
}
//
$this->session->set_flashdata('flash', 'Item baru berhasil ditambahkan');
redirect('daftarproduk');
}
}
}
in this controller I try to get 2 or more data when the checkbox is selected, when all the data is checked there is no problem at all the data entered is correct according to the selected data, which becomes a problem when I try to input the 2nd data without checking the first data, qty_masuk the value becomes 0 which should follow the data entered by the user, the problem that occurs is in qty_masuk.
function multisave($id_barang, $qty_masuk)
{
$query = "INSERT INTO `barang_masuk`( `id_barang`, `qty_masuk`)
VALUES ('$id_barang','$qty_masuk')";
$this->db->query($query);
}
Model
what should be added to solve this problem?