【发布时间】:2017-02-13 15:13:42
【问题描述】:
我正在尝试使用 insert_batch 向数据库中插入多个值。但它向我显示错误。
控制器:
public function add()
{
$data['title'] = $this->input->post('title');
$data['file'] = $this->input->post('file');
$this->user->in();
}
型号:
public function in()
{
$data['title'] = $this->input->post('title');
$data['file'] = $this->input->post('file');
foreach ($title as $key => $n) {
$insert = array(
'title' => $n,
'file' => $file[$key]
);
// echo $n."->".$file[$key].'<br>' ;
}
$this->db->insert_batch('title',$insert); //line 42 in user.php (error)
// return $query;
}
查看:
<?php echo form_open('location/add'); ?>
<div>
<input type="text" name="title[]"><br>
<input type="text" name="file[]">
</div>
<br><br>
<div>
<input type="text" name="title[]"><br>
<input type="text" name="file[]">
</div> <br><br>
<div>
<input type="text" name="title[]"><br>
<input type="text" name="file[]">
</div>
<input type="submit" name="" value="enter">
<?php echo form_close(); ?>
但是当我运行它时,它会显示如下错误:
发生数据库错误
您必须使用“set”方法来更新条目。
文件名:models/User.php
行号:47
【问题讨论】:
标签: mysql sql codeigniter foreach