我開發了一個簡單的登錄系統,它工作正常但失敗了,我需要知道爲什麼。CI--告訴我出了什麼問題
問題:如何顯示導致失敗的原因?
這裏的數據庫功能:
function login($email,$password)
{
$this->db->where("email",$email);
$this->db->where("password",$password);
$query=$this->db->get("users");
if($query->num_rows()>0)
{
foreach($query->result() as $rows)
{
//add all data to session
$newdata = array(
'user_id' => $rows->id,
'user_name' => $rows->username,
'user_email' => $rows->email,
'logged_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
return true;
}
return false;
}
而這裏的邏輯:
public function login()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
if($this->form_validation->run() == FALSE)
{
$this->signin();
}
else
{
$email=$this->input->post('email');
$password=md5($this->input->post('pass'));
$result=$this->user_model->login($email,$password);
if($result)
{
$this->dash();
}
else
{
$data['title']= 'Login Error';
$this->load->view('nav/header', $data);
$this->load->view('login', $data);
$this->load->view('nav/footer', $data);
}
}
}
我知道,因爲我重定向到登錄頁面,如果它失敗,更改標題文本的錯誤發生向我展示(僅適用於現在的測試模式)。但是,我怎樣才能找出哪裏出了問題?
這是檢查數據庫功能:
function login($email,$password)
{
$this->db->where("email",$email);
$this->db->where("password",$password);
$query=$this->db->get("users");
if($query->num_rows()>0)
{
foreach($query->result() as $rows)
{
//add all data to session
$newdata = array(
'user_id' => $rows->id,
'user_name' => $rows->username,
'user_email' => $rows->email,
'logged_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
return true;
}
return false;
}
爲什麼你粘貼兩次型號代碼? – diEcho 2013-05-10 08:27:55
備註:不要在修改密碼時使用'trim'規則 – diEcho 2013-05-10 08:42:47
你完全改變了這個問題。問另一個,保留舊的。 – diEcho 2013-05-10 08:52:13