Jc John Jc John - 3 months ago 8
PHP Question

error in codeigniter about the query

I am new in CodeIgniter . Please help me in this query, I am about to get user_typeid. Here is my model query code which has an error in line 12,


Severity: Error

Message: Call to undefined function get()


What is throwing that error?

<?php
class Login_model extends MY_Model {
function validate($data)
{
$condition = "user_email =" . "'" . $data['username'] . "' AND " . "user_password =" . "'" . $data['password'] . "'";
$this->db->select('usertype_id');
$this->db->from('user');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db-get();
if($query->num_rows() == 1) {
return $query->row_array();
}
else {
return NULL;
}
}
}
?>

Answer

You're missing a right arrow > before get()

$query = $this->db-get();

This is like you're doing $this->db minus get(), and get is not a function.

Should be this:

$query = $this->db->get();