I am having an issue, it should be very simple but I can't seem to fix it. I am trying to grab a user id from a user by searching the username in the database. But i am just getting a null value.. Please let me know what I might be doing wrong.
Here is the code for the query:
private function get_u_id($user){
$sql = "SELECT * FROM users WHERE 'username'=?";
$query = $this->db->query($sql, array($user));
foreach($query->result as $row){
return $row['id'];
}
}
I am storing this info in a session so here is that code:
$user_session_data = array(
'user'=>$p_info['username'],
'email' => $this->get_user_email($p_info['username']),
'u_id' => $this->get_u_id($p_info['username']),
'validated' => TRUE
);
//set a session, (username, email, user_id)
private function set_session($user_data) {
$this->session->set_userdata($user_data);
}
And when I output this session using print_r() it looks like this
[user_data] => [user] => wilprim [email] => [u_id] => [validated] => 1