我试图在codeigniter框架中的数据库中插入值,但得到此错误。如何从数据库中获取自动递增的ID值
A Database Error Occurred
Error Number: 1054
Unknown column '0' in 'field list'
INSERT INTO `admin_table` (`0`) VALUES ('')
Filename: C:\xampp\htdocs\CI\system\database\DB_driver.php
Line Number: 331
Admin_table
* ID INT(10)自动增量的主键
*名称:VARCHAR(255)
*电子邮件:VARCHAR(255)
*名称:varchar(255)
*联系人:int(10)
查看:
<form>
<input type="hidden" name="ID">
<legend>Add Data</legend>
<label>Name</label>
<?php echo form_input(['name'=> 'Name','placeholder'=>'Name',]);?>
<label>Email</label>
<?php echo form_input(['name'=> 'Email','placeholder'=>'Email']);?>
<label>Designation</label>
<?php echo form_input(['name'=> 'Designation','placeholder'=>'Designation']);?>
<label>Contact</label>
<?php echo form_input(['name'=> 'Contact','placeholder'=>'Contact']);?>
<?php echo form_reset(['name'=>'Reset','value'=>'Reset']); ?>
<?php echo form_submit(['name'=>'submit','value'=>'Add']) ?>
</form>
控制器:
$this->load->library('form_validation');
$post= $this->input->post();
$this->load->model('model');
if($this->model->add_data($post)){
//insert succesfully
}
else{
//insert failed
}
型号:
$this->db->insert('admin_table',$array);
$last_id=$this->db->insert_id();
return $last_id;
当我使用控制器的print_r($ POST),它不是打印字段的值但显示的价值在url.Where我错了,请告诉我。
在此先感谢。
添加您的数据库插入查询。我认为您的数据库查询是不正确的。 –
我已经插入像这样:$ this-> db-> insert('admin_table',$ array); – user6891871
你是从哪里来的?