I am learning CodeIgniter through Anthony Viponds Youtube tutorial. At creating and register and login system, I have finished the lesson, but have some issues.
I am able to register which can be seen in the DB. So for the test purposes I've made an account with username 'test' and password 'test' which is stored in the DB as 098f6bcd4621d373cade4e832627b4f6 in the MD5 hash. The hash is validly stored and decrypted using online decription services. So there is not trim-like issue.

When I tried to login with posting the content to the validate method, I received the index page, which was meaning that the num_rows method was returning 0 instead of 1 which indicates the valid login.
membership_model.php
function validate() {
$this->db->where('username', $this->input->post('username'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get('users');
print_r($this->db->queries);
if($query->num_rows == 1) {
return true;
}
else {
echo "Wrong";
}
}
login.php
function validate_credentials() {
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if ($query) {
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
echo 'here #1';
$this->session->set_userdata($data);
redirect('site/members_area');
}
else
{
$this->index();
}
}
As you see, I also made a 'here #1' echo which would indicate that I reached that point. But as I mentioned it redirects me to the index which means the else is executed in login.php.
So it's clear that the validate() from membership_model didn't return anything TRUE.
I used
print_r($this->db->queries);
to see the output and the actual SQL query.
So the output returned the query.
SELECT * FROM `users` WHERE `username` = 'test' AND `password` = '098f6bcd4621d373cade4e832627b4f6'
The next step was to run this query in phpMyAdmin. Which returned a result. Which means this query was valid.
So the question is: Why does the num_rows return 0 while the same query in phpMyAdmin returns 1 (valid result) ?

