Welcome Guest, Not a member yet? Register   Sign In
reading session userdata problem
#1

[eluser]illuzionist[/eluser]
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:

Code:
$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:
Code:
echo $this->session->userdata('username');

but when I try to echo out firstname, lastname, admin or id I get this error:
Quote: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:

Code:
$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'));




Theme © iAndrew 2016 - Forum software by © MyBB