title: Message: Undefined property: Users::$form_validation
body: <p>im currently trying to change my application from MySQL database to MongoDB database. My project requires to compare two of these, and my MySQL code was working and now it gives me this error. </p>
  
  <p>Stack Trace:</p>
  
  <blockquote>
    <p>A PHP Error was encountered Severity: Notice Message: Undefined property: <code>Users::$form_validation</code> Filename: <code>controllers/users.php</code> Line Number: 26</p>
  </blockquote>
  
  <p>Error line: </p>
  
  <pre><code>$this-&gt;form_validation-&gt;set_rules('username','Username','trim|required|min_length[4]|xss_clean');   
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php
  class Users extends CI_Controller{
      public function register(){ 
          $this-&gt;form_validation-&gt;set_rules('first_name','First Name','trim|required|max_length[50]|min_length[2]|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('last_name','Last Name','trim|required|max_length[50]|min_length[2]|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('email','Email','trim|required|max_length[100]|min_length[5]|xss_clean|valid_email');
          $this-&gt;form_validation-&gt;set_rules('username','Username','trim|required|max_length20]|min_length[6]|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('password','Password','trim|required|max_length[20]|min_length[6]|xss_clean');
          $this-&gt;form_validation-&gt;set_rules('password2','Confirm Password','trim|required|max_length[50]|min_length[2]|xss_clean|matches[password]');
          if($this-&gt;form_validation-&gt;run() == FALSE){
              $data['main_content']='users/register';
              $this-&gt;load-&gt;view('layouts/main',$data);    
          }else{
              if($this-&gt;User_model-&gt;create_member()){ 
                  $this-&gt;session-&gt;set_flashdata('registered','Registered successfully');
                  redirect('home/index'); 
              }
          }
      }
  
      public function login(){
          //$this-&gt;load-&gt;model('user_model');
          $this-&gt;form_validation-&gt;set_rules('username','Username','trim|required|min_length[4]|xss_clean');      
          $this-&gt;form_validation-&gt;set_rules('password','Password','trim|required|min_length[4]|max_length[50]|xss_clean');        
  
          $collection = $this-&gt;database-&gt;users;
  
          if($this-&gt;form_validation-&gt;run() == FALSE){
  
              $this-&gt;session-&gt;set_flashdata('login_failed', 'Sorry, this username doesn't exist.');
              redirect('home/index');
          } else {
  
          $username=$_POST['login'];
          $password=$_POST['password'];
  
          $user_id = $collection-&gt;findOne(array('username' =&gt; $username, 'password' =&gt; md5($password)));
            // $username = $this-&gt;input-&gt;post('username');
            // $password = $this-&gt;input-&gt;post('password');
  
  
             $user_id = $this-&gt;User_model-&gt;login_user($username,$password);
  
  
             if($user_id){
  
                 $user_data = array(
                         'user_id'   =&gt; $user_id,
                         'username'  =&gt; $username,
                         'logged_in' =&gt; true
                  );
  
                 $this-&gt;session-&gt;set_userdata($user_data);
  
                 redirect('home/index');
              } else {
  
                  $this-&gt;session-&gt;set_flashdata('login_failed', 'Sorry, this username doesn't exist.');
                  redirect('home/index');
              }
          }
      }
  
      public function logout(){
  
          $this-&gt;session-&gt;unset_userdata('logged_in');
          $this-&gt;session-&gt;unset_userdata('user_id');
          $this-&gt;session-&gt;unset_userdata('username');
          $this-&gt;session-&gt;sess_destroy();
  
          redirect('home/index');
      }
  }
  </code></pre>