[eluser]GesterX[/eluser]
I have a simple login function in my model as follows:
Code:
<?php
class LoginModel extends CI_Model {
function __construct() {
parent::__construct();
$this->load->library("session");
}
function check_user($username, $password) {
$whereArray = array('name' => $username, 'password' => md5($password));
$this->db->select('name, password')->from('players')->where($whereArray)->limit(1);
$query = $this->db->get();
if ($query->num_rows() > 0) {
$sess = $query->row();
$this->session->set_userdata($sess); // do session
$ar_data = array('login' => TRUE);
$this->session->set_userdata($ar_data);
return TRUE;
} else {
return FALSE;
}
}
}
And this is called from my controller in the following function:
Code:
function process_login() {
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == TRUE) {
$username = $this->input->post('username');
$password = $this->input->post('password');
if ($this->LoginModel->check_user($username, $password) == TRUE) {
$this->load->view('login/success');
} else {
$this->session->set_flashdata('message',
'Sorry, username and or password Is Wrong !!');
redirect('login');
}
} else {
$this->load->view('login/index');
}
}
Whenever I try to do a login (with correct or incorrect credentials) I get the following error:
Fatal error: Call to a member function num_rows() on a non-object in C:\PROJECT-PATH\LoginModel.php on line 13
Any ideas guys? I've been banging my head and googling for about2 hours with no luck!