Use ci to write the logon code. use $ this-& amp; gt; db-& amp; gt; when you query the database to verify the account password, the returned value is always null. The following is the function code verified in the Controller: {code ...} the code in the model is as follows: {code ...} use ci to write the logon code, and use $ this-> db-> where to query the database to verify the account password. The returned value is always null.
The function code verified in the controller is as follows:
public function validate_credentials(){ $this->load->model('Bookmark_models'); $query = $this->Bookmark_models->where(); if ($query){ $data = array('username' => $this->input->post('username'), 'is_loggrd_in' => true); $this->session->set_userdata($data); $this->load->view('logged_in_area'); }else { $this->login(); }
The code in the model is as follows:
public function where(){ $this->db->where('username',$this->input->post('username')); $this->db->where('passwd',sha1($this->input->post('password'))); $query = $this->db->get('user'); if ($query->num_rows == 1){ return true; }
Reply content:
Use ci to write the logon code, and use $ this-> db-> where to query the database to verify the account password. The returned value is always null.
The function code verified in the controller is as follows:
public function validate_credentials(){ $this->load->model('Bookmark_models'); $query = $this->Bookmark_models->where(); if ($query){ $data = array('username' => $this->input->post('username'), 'is_loggrd_in' => true); $this->session->set_userdata($data); $this->load->view('logged_in_area'); }else { $this->login(); }
The code in the model is as follows:
public function where(){ $this->db->where('username',$this->input->post('username')); $this->db->where('passwd',sha1($this->input->post('password'))); $query = $this->db->get('user'); if ($query->num_rows == 1){ return true; }
Useecho $this->db->last_query();
Output native SQL statements to the database for execution to see if there are any results.
num_rows()
It is a method rather than a property.
In addition, we do not recommend that you write this statement. We do not recommend that you do controller operations in the model.
public function login($user, $password) { return $this->db->where('username', $user) ->where('password', sha1($password)) ->get('user') ->row(); }
public function where(){ $this->db->where('username',$this->input->post('username')); $this->db->where('passwd',sha1($this->input->post('password'))); $query = $this->db->get('user'); echo $this->db->last_query();exit(); if ($query->num_rows() ){ return true; } return false;