Here is my controller
public function login() {
$this->load->model('admin_model');
$access = $this->admin_model->check_login();
$data['content'] = 'content/home';
$data['title'] = 'Admin Panel Login';
if($access) {
$data= array(
'email' => $this->input->post('email'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('admin/index/dashboard');
} else {
$this->index($page = 'home', $msg = 'failure');
}
Here is my model
public function check_login() {
$this->db->where('email', $this->input->post('email'));
$this->db->where('password', $this->input->post('password'));
$query = $this->db->get('customers');
return (bool) $query->num_rows;
}
So what I have been working on is a function in my Admin constructor that will ensure that users cannot access any page until they are logged in. The problem is that when I go to admin/login, it is setting is_logged_in to true, even though the check_login function should be returning as false. It’s saying that it is finding a row, even though there is only 1 row in my DB right now which it shouldn’t be matching.
I’m new to CI, so please be gentle. 🙂
num_rows()is a method (not a property) and should be used more like this: