【发布时间】:2015-12-26 13:55:36
【问题描述】:
我正在尝试在 codeigniter 中验证我的插入数据
问题是代码返回了重复条目的页面错误。我想用错误消息将失败扔到主页。
这是我的代码:
$data = array(
'heheId' => $this->input->post('heheId'),
'userId' => $this->input->post('userId')
);
$this->db->insert('tentarasaya',$data);
if ($this->db->affected_rows() > 0){
$this->session->set_flashdata('info', "Hore sukses");
} else {
$this->session->set_flashdata('danger', "Fail insert");
}
redirect('my_home');
有答案吗?
更新: 像这样重复输入
【问题讨论】:
-
重复输入使用唯一验证
$this->form_validation->set_rules('field_name', 'Field', 'trim|required|is_unique[TABLENAME.COLUMNNAME]'); -
这是外键问题
-
并且您已在数据库中将其设置为 Unique。 删除它
标签: php mysql codeigniter activerecord mysqli