我在将数据库插入数据库时遇到问题我尝试在我的控制器中使用echo但是它没有显示任何值,这是我的表单中的代码
<form action="<?php echo base_url().'water/save_items' ?>" method="post">
<table class="purchase">
<input name="uid" value="5" type="hidden">
<tbody>
<tr>
<th>Qty</th>
<th>Brand</th>
<th>Price</th>
</tr>
<tr id="row-1">
<td>4</td><td>Perrier</td><td>216</td>
</tr>
<tr id="row-2">
<td>7</td><td>Volvic</td><td>315</td>
</tr>
<tr id="row-3">
<td>8</td><td>Borjomi</td><td>544</td>
</tr>
</tbody>
<input name="pid[]" value="1" type="hidden"><input name="item[]" value="4" type="hidden">
<input name="pid[]" value="2" type="hidden"><input name="item[]" value="7" type="hidden">
<input name="pid[]" value="3" type="hidden"><input name="item[]" value="8" type="hidden">
</table><br>
<button type="submit" class="btn btn-success product-button">Checkout</button>
</form>
CONTROLLER
public function save_items()
{
$uid = $this->input->post('uid');
$pid = $this->input->post('pid[]');
$item = $this->input->post('item[]');
for($x = 0; $x < count($pid); $x++)
{
$data = array("uid"=>$uid, "pid"=>$pid[$x], "item"=>$item[$x]);
$this->db->insert('cart', $data);
}
$this->load->helper('url');
$this->load->view('headerlogin');
$this->load->view('products');
$this->load->view('footer');
}
“uid”有一个值,但当我尝试将其插入我的数据库时,“pid”和“item”具有空值
答案 0 :(得分:2)
您必须将代码更改为:
$pid = $this->input->post('pid');
$item = $this->input->post('item');