Codeigniter Database Insert Failure
activerecord, codeigniter, insert
Solution
You can use
if($this->db->insert('Faviroute_Addresses', $address_data))
{
// Code here after successful insert
return true; // to the controller
}
Or you can use
$this->db->insert('Faviroute_Addresses', $address_data);
if($this->db->affected_rows() > 0)
{
// Code here after successful insert
return true; // to the controller
}
Problem
Currently in my controller, when adding new data, I validate the inputs, and if there are any problems it lets a user known, otherwise it passes the data to the model to insert to the database How do I now go about checking the insert statement worked correctly in the model, and let a user known if it did not. Does an insert statement like below, return true or false, which can then be returned to the controller? ``` $this->db->insert('Faviroute_Addresses', $address_data); ``` Thanks for any help