failed to POST $items['id']
data array into database if i use form_hidden('product_id[]', $items['id'])
,however if i use form_input('product_id[]', $items['id'])
all $items['id']
array can be insert into database without error,i need help because i want to use form_hidden()
.
view(html) :
foreach ($item as $items) { ?>
<tr>
<td class="text-center">
<div class="avatar avatar-md">
<img src="./assets/avatars/face-3.jpg" alt="..." class="avatar-img rounded-circle">
</div>
</td>
<td class="text-center">
<p class="mb-0"><?= $items['product_name'] ?></p>
<small class="mb-0">[ <?= $items['serial_number'] ?> ]</small>
</td>
<td>
<div class="row justify-content-center">
<div>
<small>
B :
<?php
if($items['berat']!=0)
{
echo $items['berat'].' g';
}else{
echo '-';
}
?>
</small>
<br>
<small>
P :
<?php
if($items['panjang']!=0)
{
echo $items['panjang'].' cm';
}else{
echo '-';
}
?>
</small>
<br>
<small>
L :
<?php
if($items['lebar']!=0)
{
echo $items['lebar'].' cm';
}else{
echo '-';
}
?>
</small>
</div>
<div class="ml-3">
<small>
Sz :
<?php
if($items['saiz']!=0)
{
echo $items['saiz'];
}else{
echo '-';
}
?>
</small>
<br>
<small>
Sb :
<?php
if($items['serial_berat']!='')
{
echo $items['serial_berat'];
}else{
echo '-';
}
?>
</small>
<br>
<small>
M :
<?php
if($items['mutu']!='')
{
echo $items['mutu'];
}else{
echo '-';
}
?>
</small>
</div>
</div>
</td>
<td class="w-25 text-center">
<p class="mb-0"><?= $items['keterangan'] ?></p>
</td>
<td class="text-center"><?= $items['harga'] ?></td>
</tr>
<?php echo form_hidden('product_id[]', $items['id']); ?>
<?php } } ?>
controller :
//CONTROLLER
$arr_buyID = $this->input->post('product_id[]');
$buy = array(
'cust_id' => $this->input->post('things'),
'seller' => $this->data['user_profile']['full_name'],
'total_harga' => $this->input->post('jumlah'),
'created_date'=>date("Y-m-d H:i:s"),
);
$this->db->insert('ci_buy', $buy);
$buy_id = $this->db->insert_id();
for($i=0;$i<count($arr_buyID);$i++){
$res = explode('_',$arr_buyID[$i]);
$item = array(
'buy_id'=>$buy_id,
'status'=>1
);
$this->db->where('id', $arr_buyID[$i]);
$this->db->update('ci_buy_product', $item);
}
sample array print_r($item)
:
Array ( [0] => Array ( [id] => 13 [buy_id] => [product_name] => QWEW [serial_number] => BL00000013 [dulang] => [category] => [mutu_id] => 1 [serial_berat] => 0.370 [berat] => 1.00 [saiz] => 2 [panjang] => 3.00 [lebar] => 0.00 [harga] => 1.00 [keterangan] => asd [status] => 2 [picture] => [mutu] => 999 ) [1] => Array ( [id] => 14 [buy_id] => [product_name] => ASD [serial_number] => BL00000014 [dulang] => [category] => [mutu_id] => 1 [serial_berat] => 0.370 [berat] => 1.00 [saiz] => 2 [panjang] => 3.00 [lebar] => 0.00 [harga] => 12.00 [keterangan] => asdasd [status] => 2 [picture] => [mutu] => 999 ) ) 1
my view if i use form_input
which show the $item['id']
(13 and 14) inside form_input
,this method no error,if i hide the form input using form_hidden
,it will show error