【发布时间】:2016-08-03 23:16:36
【问题描述】:
在数据库中创建/插入数据时遇到问题。每当我提交表单时,它都会使用 form_validation 返回错误。它适用于我以前的数据库,但现在不适用。我怀疑它在数据类型枚举上。
控制器:
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');
}
}
}
查看:
<select class="form-control" id="status" name="status">
<option value="0">Incomplete</option>
<option value="1">Complete</option>
</select>
【问题讨论】:
-
你能解释更多吗显示你的验证码
-
还请包括您遇到的错误
-
感谢您的快速响应。看看我上面的编辑。
-
$this->session->set_flashdata('error', ' 添加项目时出错!');这个错误。表示未插入数据。
-
您只是在两个输入字段上应用验证.....
标签: php mysql codeigniter enums