我开发了一个简单的登录系统,它运行正常但失败了,我需要知道原因
问题:如何显示导致失败的原因.这不是验证错误,而是数据传递给MySQL或查询以某种方式失败的错误
这是db函数:
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); } } }
我知道错误发生在我重定向到登录页面如果失败并更改标题文本以显示我(现在只在测试模式下) – 但我怎么能找出查询出了什么问题?
如果y的行为符合预期,您可以使用log_message并检查日志:
http://ellislab.com/codeigniter/user-guide/general/errors.html
我通常只使用echo’< pre>‘;的print_r($查询 – >结果());模具;在$query形成之后.它更快.