CodeIgniter Forums

Full Version: Check affected_rows() from delete query
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]BandonRandon[/eluser]
Hi,

I'm new to CI. I'm trying to create an employee module and part of that is the delete function. I have created the delete function and it works but for some reason the function I'm using to validate it is returning false.

Here is in my model
Code:
public function delete_employee($id){
        $this->db->delete('employees_table', array('id' => $id));
        if ($this->db->affected_rows() > 0) {
            return TRUE;
        }
        return FALSE;
    }

and my controller
Code:
public function delete_employee($id=''){
            if(empty($id)){
                    $this->session->set_flashdata('error', "error");
                redirect('admin');
            }
            $result = $this->my_model_m->delete_employee($id);
            if($this->employee_m->delete_employee($id)){
                $this->session->set_flashdata('success', "employee Deleted");
                    redirect('admin');
            }
            else{
                $this->session->set_flashdata('error', "error");
                redirect('admin');


            }
        }

This is returning the flash data "error" but deleting the row. If I do a select query it returns true and shows the correct message.