title: how to check if username already exists in codeigniter my error
body: <p>My controler cod is:</p>
  
  <pre><code>function register()
      {
  
  
          if(isset($_POST['register'])){
  
              $this-&gt;form_validation-&gt;set_rules('username','Username','required');
              $this-&gt;form_validation-&gt;set_rules('email','Email','required');
              $this-&gt;form_validation-&gt;set_rules('password','Password','required');
           // 
              if($this-&gt;form_validation-&gt;run () == true){
                  echo 'Form Validate';
  
                  $data = array(
                      'username'=&gt;$_POST['username'],
                      'email'=&gt;$_POST['email'],
                      'password'=&gt;strtoupper(hash('whirlpool',$_POST['password']))
                      );
  
                  $this-&gt;db-&gt;insert('accounts',$data);
                  $this-&gt;load-&gt;model("usuarios_model");
                  if($this-&gt;usuarios_model-&gt;check_user_exist($data['username'])){
      echo "already user exist";
    }{
      $this-&gt;db-&gt;insert('accounts',$data);
      redirect("painel/index");
     }
  
              }
  
          }
          $this-&gt;load-&gt;view("painel/register");
      }
  </code></pre>
  
  <p>[![enter image description here][2]][2]</p>
  
  <p>It registers an user even though the username already exists.</p>
  
  <p>Where is the mistake?</p>