I want to add the data of the user from the database in the set_userdata() function in Code Igniter and my code is not working. When i display the userdata() all of the fields from the database didnt displayed. Can you check whats wrong? NEWBIE IN CODE IGNITER HERE :(
if($this->form_validation->run()){
$this->load->model('model_users');
$userinfo=$this->model_users->get_user_info();
$data = array(
'empID' => $userinfo->empID,
'email' => $userinfo->email,
'emp_name' => $userinfo->emp_name,
'address' => $userinfo->address,
'position' => $userinfo->position,
'usertype' => $userinfo->usertype,
'is_logged_in' => 1
);
$this->session->set_userdata($data);
redirect('main/home');
} else{
$this->login();
}
and here is the code from the model
public function can_log_in(){
$this->db->where('email', $this->input->post('email'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get('employee');
if($query->num_rows() == 1){
return true;
} else {
return false;
}
}
public function get_user_info(){
$query = $this->db->get_where('employee',array('email'=> $this->input->post('email'),'password'=> md5($this->input->post('password'))));
foreach ($query->result() as $userinfo)
{
echo $userinfo->empID;
echo $userinfo->email;
echo $userinfo->emp_name;
echo $userinfo->address;
echo $userinfo->position;
echo $userinfo->usertype;
}
return $userinfo;
}