Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php codeigniter中关于查询的错误_Php_Codeigniter_Model - Fatal编程技术网

Php codeigniter中关于查询的错误

Php codeigniter中关于查询的错误,php,codeigniter,model,Php,Codeigniter,Model,我对CodeIgniter是新手。请在这个查询中帮助我,我将获取用户\u typeid。这是我的模型查询代码,第12行有一个错误 严重性:错误 消息:调用未定义的函数get() 这是什么错误 <?php class Login_model extends MY_Model { function validate($data) { $condition = "user_email =" . "'&q

我对CodeIgniter是新手。请在这个查询中帮助我,我将获取用户\u typeid。这是我的模型查询代码,第12行有一个错误

严重性:错误

消息:调用未定义的函数get()

这是什么错误

<?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;
                }
        }
}
?>

get()

这就像你在做
$This->db
减去
get()
,而
get
不是一个函数

应该是这样的:

$query = $this->db->get();
请尝试下面的代码

你也可以在下面这样的地方使用

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;
    }
}

您在$data['username']附近收到了用户电子邮件,应该是用户用户名吗?没问题,先生,在我的表格中,我输入了用户名,但在我的数据库中,它的用户电子邮件您也可以使用
$this->db->where('username',$data['username'])
$this->db->where('password',$data['password'))
error很明显,您的
get()有问题。
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;
    }
}