I have a table in my app named admin and I’m using the code below to select a record based off of submitted email and password. I’m getting “undefined property stdclass” errors for first_name, last_name and admin_role. I’ve triple checked and those are the names of the columns in my table. What am I doing wrong? I am autoloading the database and session libraries. Is it okay to set session data in a model?
Model Code:
public function can_sign_in() {
$this->db->select('admin_id', 'first_name', 'last_name', 'admin_role');
$this->db->where('admin_email', $this->input->post('admin_email'));
$this->db->where('admin_password', md5($this->input->post('admin_password')));
$query = $this->db->get('admin');
if($query->num_rows() == 1) {
foreach ($query->result() as $row) {
$admin[] = array(
'admin_id' => $row->admin_id,
'first_name' => $row->first_name,
'last_name' => $row->last_name,
'admin_role' => $row->admin_role
);
$this->session->set_userdata($admin);
}
return true;
} else {
return false;
}
}
selectonly takes 2 parameters. A string with with the fields to select, and a boolean saying if it should escape the string with backticks or not.You’re passing 4 parameters. You want to pass just one, a string with the comma separated fields: