Welcome Guest, Not a member yet? Register   Sign In
[Solved] Stuck On Login Num Rows Error
#1

[eluser]riwakawd[/eluser]
I am making my own form validation method because can have more control over it. But when I try to login it throws a num row error message. On my users library file.

Error

Message: Undefined property: CI_DB_mysqli_driver::$num_rows

I am unsure why it throws a num row error I have tried $user_query->num_rows() ==1

Here is my Library file.

Code:
public function login() {
            $password = $this->CI->input->post('password');
            $username = $this->CI->input->post('username');

            $user_query = $this->CI->db->select('*')
            ->where('username', $username)
            ->where('password',  $this->CI->encryption->hash_password().hash('sha512', $password).$this->CI->encryption->generate_salt())
            ->where('status', "1")
            ->from('user');
            if($user_query->num_rows) {

                  $data = array(
                        'ip' => $this->CI->input->ip_address(),
                        'user_id' => $this->CI->session->userdata('user_id')
                  );

                  $this->db->where('user_id', $user_id);
                  $this->db->update('user', $data);

                  return true;

            } else {

                  return false;
              
            }
      }

Here is My Controller Login


Code:
public function index() {
            if(($this->input->server('REQUEST_METHOD') == 'POST') && $this->validate()) {

                  $data = array(
                      'username' => $this->input->post(),
                      'user_id' => $row->user_id,
                      'isLogged' => true
                  );
                  $this->db->get('user');
                  $this->session->set_userdata($data);

                  redirect('dashboard');
            }

            if (array_key_exists('warning', $this->error)) {
                  $data['error_warning'] = $this->error['warning'];
            } else {
                  $data['error_warning'] = '';
            }

            if (array_key_exists('username', $this->error)) {
                  $data['error_username'] = $this->error['username'];
            } else {
                  $data['error_username'] = '';
            }

            if (array_key_exists('password', $this->error)) {
                  $data['error_password'] = $this->error['password'];
            } else {
                  $data['error_password'] = '';
            }

            $data['action'] = site_url("login");

            if (!"" == trim($this->input->post('username'))) {
                  $data['username'] = $this->input->post('username');
            } else {
                  $data['username'] = '';
            }

            if (!"" == trim($this->input->post('password'))) {
                  $data['password'] = $this->input->post('password');
            } else {
                  $data['password'] = '';
            }

            $this->load->view('template/common/login', $data);
      }

      protected function validate() {
            if (!"" == trim($this->input->post('username')) || !"" == trim($this->input->post('password')) || !$this->users->login($this->input->post('username'), $this->input->post('password'))) {
                  $this->error['warning'] = $this->lang->line('error_login');
            }

            return !$this->error;
      }
#2

[eluser]treenef[/eluser]
$user_query->num_rows

Instead try

if ($user_query->num_rows() > 0)
#3

[eluser]riwakawd[/eluser]
[quote author="treenef" date="1403523725"]$user_query->num_rows

Instead try

if ($user_query->num_rows() > 0)[/quote]

I had to do a couple of other things but all done now.




Theme © iAndrew 2016 - Forum software by © MyBB