title: Trying to get property of non-object when username is incorrect using CodeIgniter
body: <p>I am using password_verify to check the password is correct or not which is working perfectly. My issue is when the user entered the wrong username clicked on login button than I am getting the error that <code>"Trying to get property of non-object"</code>. </p>
  
  <p>Instated of error it should display the validation error message.</p>
  
  <p>If I enter the correct username and wrong password than I am getting the proper validation error message(Password is invalid) but If I enter the wrong username and correct password then I am getting the error <code>"Trying to get property of non-object"</code>.` 
  Would you help me out in this?</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public function login_user()
   {
  
      $this-&gt;form_validation-&gt;set_error_delimiters('', '');
      $this-&gt;form_validation-&gt;set_rules('user_email', 'Email', 'trim|required|valid_email');
      $this-&gt;form_validation-&gt;set_rules('user_password', 'Password', 'trim|required|xss_clean|callback_check_password_database');
  if ($this-&gt;form_validation-&gt;run() == FALSE)
  {
    $this-&gt;load-&gt;view('login');
  }
  else
  {
    //redirect(base_url('Student_controller/index'),'refresh'); 
  }
  
   }
  
   /*Checking the login details*/
  function check_password_database($user_password)
  {
      $a_username=$this-&gt;input-&gt;post('user_email');
  if (empty($a_username)) {
           $this-&gt;form_validation-&gt;set_message('check_password_database','Email is Invalid');
  }
  else{
     $password_fetch=$this-&gt;access_model-&gt;password_fetch($a_username);
     if(password_verify($user_password, $password_fetch))
      {
       redirect('Student_controller/index','refresh'); 
      }
      else{
         $this-&gt;form_validation-&gt;set_message('check_password_database','Password is Invalid');
         return FALSE;
    }
  }
  }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public function password_fetch($username)
  {
          $query=$this-&gt;db-&gt;select('emp_password')
                  -&gt;from('employee_info')
                  -&gt;where('emp_email',$username)
                  -&gt;get();
  $result = $query-&gt;row();  
  return $fetch_pass=$result-&gt;emp_password;
  
  }
  </code></pre>