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

First, the insert() method returns false on an error, so you can start by checking the returned value. Then, you can check the $error['code'] value and redirect to instruments/duplicate if it matches your error code. If you haven't redirected yet, you can return the $error['message'] if it is set. Finally, you can redirect to instruments/addFail, since you have no other options in your original code.

PHP Code:
if ($this->db->insert('instrument'$data)) {
    
redirect('instruments/addSuccess');
}

$error $this->db->error();
if (
$error['code'] == 1062) {
    
redirect('instruments/duplicate');
}

if (isset(
$error['message'])) {
    return 
$error['message'];
}

redirect('instruments/addFail'); 
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