我正在尝试在 codeigniter 中执行选择查询,并且我创建了如下相同的函数:
public function validate(){
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password1'));
$type = $this->security->xss_clean($this->input->post('utype'));
$password=md5($password);
$this->db->select('*');
$this->db->from('ci_users');
$this->db->where('email', $username);
$this->db->where('password', $password);
$this->db->where('utype', $type);
// Run the query
$query = $this->db->get();
// Let's check if there are any results
if($query->num_rows == 1)
{
// If there is a user, then create session data
$row = $query->row();
$data = array(
'userid' => $row->id,
'fname' => $row->fname,
'lname' => $row->lname,
'email' => $row->email,
'utype' =>$row->utype,
'phone' =>$row->mobile,
'city' =>$row->city,
'state' =>$row->state,
'country' =>$row->country,
'validated' => true
);
$this->session->set_userdata($data);
echo '<pre>';print_r($data); exit();
//return true;
}
else
{
echo "OPPS some error";
//return false;
}
}
它总是显示错误,即使我输入了正确的用户名和密码。为什么选择查询不运行?我做错了什么。请帮助我。
最佳答案
你习惯了:
if($query->num_rows == 1)
更正如下:
if($query->num_rows() == 1)
关于php - 选择查询未在 codeigniter 中执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41061934/