title: CodeIgniter Callback not working for user login
body: <p>I have checked all questions of this type but none of them works for me. Hope I would get some help here. I have a controller named index and a model named Index_model. I have write user login and signup functions in the index controller and done data related queries in model everything is working fine except the codeigniter callback function.</p>
  
  <p>When I try to validete user login details by using the callback each time it returns false and when I removed callback it is working fine. I am not getting where I am doing wrong. Please find the code below for my controller and model. Thanks in advance.</p>
  
  <p>Controller:</p>
  
  <pre><code>class Index extends CI_Controller{
  
      public function __construct(){
          parent:: __construct();
          $this-&gt;load-&gt;helper('url');
          $this-&gt;load-&gt;model('index_model');
      }
  
     public function signin(){
          $this-&gt;load-&gt;helper('form');
          $data['title'] = "Sign In";
          $data['headline'] = "Sign In";
          $data['introduction'] = "Sign In to manage your business, clients and more!";
          $data['include'] = "user/signin";
          $this-&gt;load-&gt;view('template/template', $data);
      }
  
      public function login(){
          $this-&gt;load-&gt;helper('url');
          $this-&gt;load-&gt;helper('form');
          $this-&gt;load-&gt;library('form_validation');
  
          $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'required|callback_validate_login');
          $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required|md5');
  
          if($this-&gt;form_validation-&gt;run() == TRUE){
              $data['msg'] = "User Login Successfully!!";
              $this-&gt;load-&gt;view('user/home', $data);
          }else{
              $this-&gt;signin();
          }
  
      }
  
      public function validate_login(){
          $this-&gt;load-&gt;library('form_validation');
  
          $result = $this-&gt;index_model-&gt;validate_user();
          if($result == TRUE){
              return TRUE;
          }else{
              $this-&gt;form_validation-&gt;set_message('validate_login', 'Incorrect username / password.');
              return FALSE;
          }
      }
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>class Index_model extends CI_Model{
      public function __construct(){
          $this-&gt;load-&gt;database();
      }
  
      /******User Login*************/
      public function validate_user(){
          $username = $this-&gt;input-&gt;post('username');
          $password = $this-&gt;input-&gt;post('password');
  
          $this-&gt;db-&gt;where('username', $username);
          $this-&gt;db-&gt;where('password', $password);
          $query = $this-&gt;db-&gt;get('user');
  
          if($query-&gt;num_rows() == 1){
              return TRUE;
          }else{
              return FALSE;
          }
      }
  }
  </code></pre>
  
  <p>Please, review My code it will be a great help.</p>