Welcome Guest, Not a member yet? Register   Sign In
Adding Items to Session Data
#1

[eluser]surf66[/eluser]
Hello...

In my system, when a user logs in, their username is added into the session data.

I would also like to run a query in order to retrieve their user_id from the database and add this into the session data as well. It is a pretty straight forward query and all usernames in the db are unique so every time I should be pulling out just one id from the db, there should be no problems there.

Below is my login function where I am setting my session data. If anyone could help, all I want to do is grab the users id from db where it matches their username and set it in session data

Thank you in advance Smile

Code:
function login(){
  $username = $this->input->post('username');
  //get the user id and set it in the session data
  $this->db->select('user_id');
  $this->db->from('student_users');
  $this->db->where('user_username', $username);  
  $query = $this->db->get();
  return $query->row_array();

  $user_id = $query['user_id'];


  $data = array(
   'username' => $this->input->post('username'), //this works fine
   'user_id' => $user_id, //this is where i want to set the user_id in session data
   'logged_in' => TRUE
  );
  $this->session->set_userdata($data);
} //function login()


Messages In This Thread
Adding Items to Session Data - by El Forum - 01-09-2013, 06:15 AM
Adding Items to Session Data - by El Forum - 01-09-2013, 06:27 AM
Adding Items to Session Data - by El Forum - 01-09-2013, 06:38 AM
Adding Items to Session Data - by El Forum - 01-09-2013, 09:40 AM
Adding Items to Session Data - by El Forum - 01-09-2013, 11:24 AM
Adding Items to Session Data - by El Forum - 01-10-2013, 01:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB