Php codeigniter使用枚举字段将数据插入数据库
我在数据库中创建/插入数据时遇到问题。每当我提交表单时,它都会使用表单验证返回一个错误。它适用于我以前的数据库,但现在不行。我怀疑它在数据类型enum上 控制器:Php codeigniter使用枚举字段将数据插入数据库,php,mysql,codeigniter,enums,Php,Mysql,Codeigniter,Enums,我在数据库中创建/插入数据时遇到问题。每当我提交表单时,它都会使用表单验证返回一个错误。它适用于我以前的数据库,但现在不行。我怀疑它在数据类型enum上 控制器: public function create_item() { $data = array( 'checklist_id' => $this->input->post('checklist_id'), 'title' => $this->input->post('title'),
public function create_item() {
$data = array(
'checklist_id' => $this->input->post('checklist_id'),
'title' => $this->input->post('title'),
'description' => $this->input->post('description'),
'type' => $this->input->post('type'), //with enum type
'section' => $this->input->post('section'),
'order_no' => $this->input->post('order_no'),
'status' => $this->input->post('status'), //with enum type
'date_created' => $this->input->post('date_created')
);
$this->form_validation->set_rules('title','Item Title','trim|required|callback_alpha_dash_space');
$this->form_validation->set_rules('order_no','Item Order','trim|required');
$this->form_validation->set_message('alpha_dash_space', '%s appears to be invalid. Must contain only alphabets.');
$this->form_validation->set_message('required', '%s field must not be empty. ');
if ($this->form_validation->run() == FALSE) {
$this->session->set_flashdata('error', ' Error adding an item!');
redirect($this->agent->referrer());
} else {
$result = $this->checklist_item_model->put_item($data);
if (!$result == TRUE) {
$this->session->set_flashdata('success', 'Item added successfuly!');
redirect('checklist_item', 'refresh');
}
}
}
视图:
残缺的
完成
在控制器中执行类似的验证
$this->form_validation->set_rules('title','ItemTitle','trim|required|callback_alpha_dash_space');
$this->form_validation->set_rules('order_no','Item Order','trim|required');
$this->form_validation->set_message('alpha_dash_space', '%s appears to be invalid. Must contain only alphabets.');
$this->form_validation->set_message('required', '%s field must not be empty. ');
if ($this->form_validation->run() == TRUE) {
// do something here
$this->session->set_flashdata('success', 'Item added successfuly!');
redirect('checklist_item', 'refresh');
}
并且在您的视图中轻松显示验证错误,您可以跟踪错误字段
<?php if(validation_errors()) { ?>
<div class="alert alert-danger"><?php echo validation_errors(); ?></div>
<p class="text-center mb30"></p>
<?php } ?>
您可以解释更多信息吗?显示您的验证代码。另外,请包括您收到的错误。感谢快速响应。查看上面的我的编辑。$this->session->set_flashdata('error','error adding an item!');这是一个错误。这意味着未插入数据。您仅在两个输入字段上应用Validation…。很抱歉,它也会返回false。
<?php if(validation_errors()) { ?>
<div class="alert alert-danger"><?php echo validation_errors(); ?></div>
<p class="text-center mb30"></p>
<?php } ?>