我對模式的功能有問題。當我把正確的管理員名稱和管理員密碼,它不起作用。相反,它給了我最後一個錯誤信息(「你沒有...」),但是如果我註釋掉模型中的第二個WHERE子句,那麼它的工作方式就像預期的那樣。使用WHERE子句時,模型總是執行else子句
型號:
function validate_admin()
{
$this->db->where('adminname',$this->input->post('adminname'));
//$this->db->where('adminpassword',md5($this->input->post('adminpassword')));
$query = $this->db->get('admin');
if($query->num_rows() == 1)
{
return TRUE;
}
}
控制器:
function validate_admin_credentials()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('adminname','Username','trim|required');
$this->form_validation->set_rules('adminpassword','Password','trim|required');
if($this->form_validation->run() == FALSE)
{
$data['main_content']='login_failed';
$this->load->view('includes/template',$data);
}
else
{
$this->load->model('admin_model');
if($this->admin_model->validate_admin())
{
$data = array(
'adminname' => $this->input->post('adminname'),
'adminpassword' => $this->input->post('adminpassword'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('/site/admin_panel');
}
else
{
echo "You don't have administration privileges";
}
}
}
我怎樣才能解決這個問題?
它不起作用。這是第二個where子句的問題.. – user3313651
'md5'移出'where'。你可以再試一次。 – lighter