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!