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;
}
}
}
?>
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();
Try code below
And you can also use where like below
function validate($data) {
// It is only going to select usertype_id
$this->db->select('usertype_id');
$this->db->from('user');
$this->db->where('user_email', $data['username']);
$this->db->where('user_password', $data['password']);
$this->db->limit(1);
$query = $this->db->get(); // missing >
// if you do not want to use == 1 you can use > 0
if ($query->num_rows() == 1) {
return $query->row_array();
} else {
return FALSE;
}
}