Say I have a form which gets populated when clicked on some link and the user is allowed to update the data and save the changes made to those fields.
$data = array('somevalue, 'somevalue');
$this->db->where('id', $this->input->post('id'))->update('links', $data);
if($this->db->affected_rows() == 1){
return TRUE;
}else{
return FALSE;
}
And when I make some changes and do the save everything works fine because it returns TRUE for affected_rows() == 1. What if I dont make any changes and do the save? No any row is going to be affected and it will return FALSE.
What would be the appropriate way to solve this issue? The main problem is that I am displaying the success message only when it returns TRUE. So there will be a problem(i.e no message is displayed) if no changes are made and save button is clicked.
Just return true.
If there is a problem with connecting to your DB you will get an error message before the application reaches that point anyway.
It is redundant code.
You should just be able to do
But you will need to check under which scenarios codeigniter return false.
P.S Cannot why not just use form validation in codeigniter to check if the fields are empty or not before going to the model?