我使用codeigniter3.0.0版本,当我运行项目时,我收到此错误,请告诉我如何修复此错误。
错误号码:1048
列'no_of_people'不能为空
INSERT INTO reservation
(no_of_people
)VALUES(NULL)
文件名:C:/xampp/htdocs/book/application/models/Books_model.php
行号:26
我的型号代码是
class Books_model extends CI_Model{
public function __construct(){
$this->load->database();
}
public function get_restaurants()
{
$sql = "SELECT restaurant_id, names FROM restaurants ";
$query = $this->db->query( $sql );
return $query->result();
}
public function insert_into_db()
{
$people =$this->input->post('no_of_people');
return $this->db->insert('reservation', array('no_of_people'=>$people));
}
}
控制器
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
类Booking_Controller扩展了CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('Books_model');
}
public function view()
{
$data['result']=$this->Books_model->get_restaurants();
$this->load->helper(array('form','url'));
$this->load->view('restaurants/booking',$data);
$this->Books_model->insert_into_db();
}
}
查看代码
<form action="<?php echo base_url();?>booking_controller/view" method="POST">
<table>
<tr>
<td>number of people</td>
<td>number of people = <input type = 'text' name='no_of_people'></td>
</tr>
<tr>
<td><input type='submit' value="Submit"></td>
</tr>
</table>
</form>
当我在no_of_people列上应用空约束时,仅在数据库中应用空值存储 Plz指导我错误的地方...... thanx