0
votes

I'm getting this error when working with CodeIgniter:

A Database Error Occurred

Error Number: 1054

Unknown column 'data' in 'field list'

SELECT `data` FROM `ci_sessions` WHERE `id` = '4j5h21j1us9nhah0qc1hqmmmevb1oa2f' AND `ip_address` = '::1'

Filename: C:/wamp64/www/life/app/delta/system/database/DB_driver.php

Line Number: 691

It's so frustrating. I've tried everything I know.

Here is the part of my controller i think the error is coming from

public function index() {
    if ($this->session->userdata('logged_in') == TRUE) {
        if ($this->session->userdata('usr_access_level') == 1) {
            redirect('users');
        } else {
            redirect('me');
        }
    }


        $data['login_fail'] = TRUE;
        $this->load->view('common/login_header');
        $this->load->view('admin/signin', $data);
        $this->load->view('common/footer');
    } else {
        $data = array(
            'usr_id' => $row->usr_id,
            'acc_id' => $row->acc_id,
            'user_name' => $row->user_name,
            'usr_access_level' => $row->usr_access_level,
            'logged_in' => TRUE
        );

        // Save data to session
        $this->session->set_userdata($data);
        if ($data['usr_access_level'] == 2) {
            redirect('me');
        } elseif ($data['usr_access_level'] == 1) {
            redirect('users');
        } else {
            redirect('me');
        }

}

Here is the Model for the controller

class _model extends CI_Model 

{

function __construct()
{
    parent::__construct();
}

public function does_user_exist($email) {
    $this->db->where('user_name', $email);
    $query = $this->db->get('users');
    return $query;
}

}

2
do you have data column? - Jyoti mishra
and also i don't see your select query in controller - Jyoti mishra
Try this $this->session->userdata('usr_access_level'); instead of $data['usr_access_level'] - Mr. ED
And where do you get this $row->usr_id from I do not see the model for it - Mr. ED
And which line here is 691? - Vaviloff

2 Answers

0
votes

modify your code to below

if ($this->session->userdata('usr_access_level') == 2) {
            redirect('me');
        } elseif ($this->session->userdata('usr_access_level') == 1) {
            redirect('users');
        } else {
            redirect('me');
        }
0
votes

Thanks for the support. The problem was from my from my database, the columns 'data' and 'id' where not available in the session table. For anyone having the same problem go to the code-igniter user guide and check for the correct session table structure.