title: how to check if username already exists in codeigniter
body: <p>I am working on a site in codeigniter.I am not so expert using framework.Here I have to check if email already exists in database.I have coded the required functionality but I am getting an error when submit the form.
  In controller i have made the following rule.</p>
  
  <p>My code is:</p>
  
  <pre><code>$this-&gt;form_validation-&gt;set_rules(
      'email', 'Email', 'trim|required|valid_email|is_unique|callback_isEmailExist'
  );
  public function isEmailExist($email) {
      $this-&gt;load-&gt;library('form_validation');
      $this-&gt;load-&gt;model('user');
      $is_exist = $this-&gt;user-&gt;isEmailExist($email);
  
      if ($is_exist) {
          $this-&gt;form_validation-&gt;set_message(
              'isEmailExist', 'Email address is already exist.'
          );    
          return false;
      } else {
          return true;
      }
  }
  </code></pre>
  
  <p>in model user the function is :</p>
  
  <pre><code>function isEmailExist($email) {
      $this-&gt;db-&gt;select('id');
      $this-&gt;db-&gt;where('email', $email);
      $query = $this-&gt;db-&gt;get('users');
  
      if ($query-&gt;num_rows() &gt; 0) {
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>When I submit the form, I am getting the following errors.</p>
  
  <p>A PHP Error was encountered</p>
  
  <p>Severity: Notice</p>
  
  <p>Message: Undefined offset: 1</p>
  
  <p>Filename: libraries/Form_validation.php</p>
  
  <h2>Line Number: 953</h2>
  
  <p>A Database Error Occurred</p>
  
  <p>Error Number: 1064</p>
  
  <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ` = 'muraddnw@gmail.com' LIMIT 1' at line 2</p>
  
  <p>SELECT * WHERE ` = 'muraddnw@gmail.com' LIMIT 1</p>
  
  <p>Filename: C:\xampp\htdocs\aunction\system\database\DB_driver.php</p>
  
  <p>Line Number: 330
  Anyone help me please.
  Thanks in advance.</p>