title: CodeIgniter login and session
body: <p>I am currently building a web for <strong>student registration</strong> and I am using CodeIgniter. I already managed to insert the form to my database and I am using email and password from the submitted form to login. I got a problem in my login page,somehow it cant check either the email or password exists on the database or not and it cant redirect to my desired page either.</p>
  
  <p>This is my controller</p>
  
  <pre><code>public function index()
  {
      $data = '';
      if($this-&gt;input-&gt;post('submit'))
      {
          $this-&gt;form_validation-&gt;set_rules('email','email','required');
          $this-&gt;form_validation-&gt;set_rules('password','password','md5|required');
  
          if($this-&gt;form_validation-&gt;run())
          {    
              $email = $this-&gt;input-&gt;post('email');
              $password = md5($this-&gt;input-&gt;post('password'));
  
              $this-&gt;load-&gt;model('testmodel','user');
  
              $member = $this-&gt;user-&gt;selectUser("WHERE email = '$email' AND password = '$password'");
  
              if($member-&gt;has_rows())
              {
                  $user_data = array(
                                  'name'  =&gt; $member-&gt;row('name'),
                                  'nisn'  =&gt; $member-&gt;row('nisn'),
                                  'email'     =&gt; $member-&gt;row('email'),
                                  'logged_in_admin' =&gt; TRUE
                             );
  
                  $this-&gt;session-&gt;set_userdata($user_data); redirect('pages/userpage/userpage');
              }else 
              {
                  $data['message'] = '&lt;div class = "error"&gt;Username and password wrong!&lt;/div&gt;';
              }
          }else 
          {
              $data['message'] = '&lt;div class = "error"&gt;' . validation_errors() .  '&lt;/div&gt;';
          }
      }
  
      $this-&gt;load-&gt;view('pages/userlogin/userlogin',$data);
  }
  </code></pre>
  
  <p>This is the selectuser function in testmodel</p>
  
  <pre><code>public function selectUser($where = '', $sort = 'DESC', $limit = '')
  {
      $query = "
          SELECT SQL_CALC_FOUND_ROWS * FROM student_table
              $where
          ORDER BY ticketnumber $sort
              $limit
      ";
      return $this-&gt;db-&gt;query($query);
  }'
  </code></pre>