我的模式功能有问题。当我输入正确的管理员名称和管理员密码时,它不起作用。相反,它给了我最后一条错误消息(“你没有......”),但是如果我在模型中注释掉第二个WHERE子句,那么它就可以正常工作了。
型号:
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";
}
}
}
如何解决此问题?
答案 0 :(得分:0)
你可以尝试一下。
<强>模型强>
$adminpassword = md5($this->input->post('adminpassword'));
$data = array('adminname' => $this->input->post('adminname'),
'adminpassword' => $adminpassword);
$query = $this->db->get_where('admin', $data);
return $query->num_rows();
<强>控制器强>
if($this->admin_model->validate_admin() > 0)
答案 1 :(得分:0)
如果您完全确定密码,可以尝试以下代码:
$this->db->where('adminpassword', md5($this->input->post('adminpassword', TRUE)));
编辑:编辑,抱歉我的英语不好