gpt4 book ai didi

php - 验证插入 codeigniter

转载 作者:行者123 更新时间:2023-11-29 11:49:03 24 4
gpt4 key购买 nike

我正在尝试验证我在 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');

有答案吗?

更新:像这样的重复条目

enter image description here

最佳答案

试试这个

$data = array(
'heheId' => $this->input->post('heheId'),
'userId' => $this->input->post('userId')
);
if (!$this->db->insert('tentarasaya',$data)) { # add if here
# Unsuccessful
$this->session->set_flashdata('danger', "Fail insert");
}
else{
# Success
$this->session->set_flashdata('info', "Hore sukses");
}
redirect('my_home');

关于php - 验证插入 codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34471990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com