Welcome Guest, Not a member yet? Register   Sign In
$this->db->error()
#1

Hi,

Just upgraded to CI 3 and am having some issues with db errors on insert.

I would like to catch when the error is a duplicate error then redirect the user to a duplicate warning page. If not duplicate, I send to a success or failed page dependent on $this->db->affected_rows(). I've tried a few things but can't seem to get it right. Any help on the code below would be great.

Code:
$this->db->insert('instrument', $data);
                
                $error = $this->db->error();
                 if (isset($error['message'])) {
                    return $error['message'];
                }
               if ($error['code'] == 1062) {
                    redirect('/instruments/duplicate', '');
                } else {
                    $affected = $this->db->affected_rows();

//echo $affected;exit();

                    if ($affected > 0) {
                        redirect('/instruments/addSuccess', '');
                    } else {
                        redirect('/instruments/addFail', '');
                    }
                }

Thanks!
Reply


Messages In This Thread
$this->db->error() - by picotrain - 09-21-2015, 09:16 AM
RE: $this->db->error() - by mwhitney - 09-21-2015, 01:01 PM
RE: $this->db->error() - by picotrain - 09-21-2015, 11:48 PM



Theme © iAndrew 2016 - Forum software by © MyBB