[eluser]eokorie[/eluser]
I am trying to write my own user authentication code. So far everything is going well, I can get the user to login but it refuses to save the username and email address into the session data. However, the user id and logged in status are saved. Hope the code below explains what I am trying to acheive. The code below is in my user model.
Code:
function login_user($username, $password)
{
$password = md5($password);
$this->db->select('id_usr','email_usr','name_usr','password_usr');
$this->db->where('name_usr',$username);
$this->db->where('password_usr',$password);
$this->db->limit(1);
$query = $this->db->get('gk_users');
$result = $query->row();
if ($query->num_rows() > 0) :
$logged_user_data = array(
'gk_login_id' => $result->id_usr,
'gk_login_email' => $result->email_usr,
'gk_login_user' => $result->name_usr,
'logged_in' => TRUE
);
$this->session->set_userdata($logged_user_data);
return true;
else:
return false;
endif;
}
With way the code is just now, when I try to log in, these are the errors I get:
--------------------------------------------------------------
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$email_usr
Filename: models/admin_model.php
Line Number: 23
--------------------------------------------------------------
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$name_usr
Filename: models/admin_model.php
Line Number: 24
--------------------------------------------------------------
If I comment out line 23 and 24, the login process works fine and the session value of id_usr is displayed. Anyone have an idea why this is not working with email_usr and name _usr?
Thanks