EllisLab text mark
Advanced Search
     
reading session userdata problem
Posted: 11 July 2012 12:00 PM
Joined: 2012-07-11
7 posts

Hello, I’m new to codeigniter and php in general so I’ve got a question.

I’m trying to save some userdata to the session just like this:

$data = array(
                
'username' => $this->input->post('username'),
                
'is_logged_in' => true,
                
'firstname' => $first_name,
                
'lastname' => $last_name,
                
'admin' => $admin,
                
'id' => $id
            
);
            
            
$this->session->set_userdata($data); 

username gets saved ok and I can echo it out just like this in some other view:

echo $this->session->userdata('username'); 

but when I try to echo out firstname, lastname, admin or id I get this error:

A PHP Error was encountered

Severity: 4096

Message: Object of class __PHP_Incomplete_Class could not be converted to string

is it maybe the problem how I get those variables from database? firstname, lastname, admin and id are all located in my database, and I get it just like this:

$first_name $this->db->query('SELECT firstname FROM users WHERE username = ?'$this->input->post('username'));
            
$last_name $this->db->query('SELECT lastname FROM users WHERE username = ?'$this->input->post('username'));
            
$admin $this->db->query('SELECT admin FROM users WHERE username = ?'$this->input->post('username'));
            
$id $this->db->query('SELECT id FROM users WHERE username = ?'$this->input->post('username'));