Reputation: 57
I am using codeigniter library please help
I don't care about the affect row's
$ci = &get_instance();
$ci->db->where('activity_id',$activity_id);
$ci->db->update('activity',$activity_data);
if(error){
return false / or error message ;
}else{
return true;
}
Upvotes: 0
Views: 2423
Reputation: 1390
You can simply know, whether your data is entered in database or not.
Model
$row = $this->db->affected_rows()
if($row ){
return true;
}else{
return false;
}
Then in controller
check condition and then you can set the flash data
and show in the view.
$this->session->set_flashdata('err_message', 'Data not updated successfully.');
remember that you need to load the session library before use it.
View
<?php
if($this->session->flashdata('err_message')){
?>
<div class="alert alert-danger">
<?php echo $this->session->flashdata('err_message'); ?>
</div>
and you can then return the $row that may be have value or empty. Hope this will help you.
Upvotes: 1
Reputation: 16
You can add it into variable first
try this
$result = $ci->db->update('activity',$activity_data);
if($result){
return true;
}else{
return $this->db->_error_message();
}
Upvotes: 0
Reputation: 127
try this
if (!(bool)$ci->db->where('activity_id',$activity_id)->update('activity',$activity_data))
{
//your error
}
Upvotes: 0