数据没有插入到表中(codeigniter),所有字段名都与视图和数据库表中的字段名一样正确。
这是我的模型
public function Insert() {
$data = array(
'Package_id' => $this->input->get_post('package_id'),
'cab_id' => $this->input->get_post('cab_id'),
'customer_name' => $this->input->get_post('customer_name'),
'customer_contact'=> $this->input->get_post('customer_contact'),
'customer_email' => $this->input->get_post('customer_email'),
'gender' => $this->input->get_post('gender'),
'no_of_seats' => $this->input->get_post('no_of_seats'));
$this->db->insert('booking',$data);
return ($this->db->affected_rows() != 1) ? false : true;
}
这是我的控制器
public function Insert() {
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="alert alert-danger">', '</div>');
$this->form_validation->set_rules('customer_name','Name','required');
$this->form_validation->set_rules('no_of_seats','Number Of Seats','required');
$this->form_validation->set_rules('customer_contact','Contact Number','required|exact_length[10]');
$this->form_validation->set_rules('gender','Gender','required');
$this->form_validation->set_rules('customer_email','Email ID','required');
$this->form_validation->set_rules('booking_date','Date','required');
$this->form_validation->set_rules('customer_address','Address','required');
if($this->form_validation->run()) {
$this->load->model('BookingModel');
if($this->BookingModel->Insert()) {
die('<div class="alert alert-success">Successfully Booked!</div><script>$("#response")[0].reset()</script>');
} else {
die('<div class="alert alert-danger">Failed to Book try again!</div>');
}
} else {
echo validation_errors();
}
}
2条答案
按热度按时间hivapdat1#
首先,你有一些语法错误。试试下面的。请记下密钥输入数据中对包标识的更改。
lo8azlld2#
像这样试试。