Hi guys i am trying to use logout code in my codigniter so due to some reason its not working properly.
Here is my logout code:
 public function Logout() {
    $this->Login_model->saveLogout();
    $this->session->sess_destroy();
    redirect('Login');
}
Here is my model code:
    public function saveLogout() {
    $recordId=$this->session->userdata('user_id');
     $ipaddress = $this->input->ip_address();
    $dataLog = array(
        'userid' => $recordId,
        'entertime' => time(),
        'ip' => $ipaddress,
        'log_operation' => 'Logout'
    );
    $dataUser = array(
        'previous_visit' => time(),
        'lastip' => $ipaddress
    );
    $this->db->insert('log_table', $dataLog);
    $this->db->set($dataUser); //value that used to update column  
    $this->db->where('id', $recordId); //which row want to upgrade  
    $this->db->update('users');  //table name
}
When i clicked on logout it is showing this below error
    Column 'userid' cannot be null
INSERT INTO `log_table` (`userid`, `entertime`, `ip`, `log_operation`) VALUES (NULL, 1534252667, '::1', 'Logout')
Can anyone help me what is the problem
Thanks in advance.
 
    