title: Check if the username already exists with MySQLi
body: <p>I try to check if the username and email from input fields already exists in my database before to create a new user.</p>
  
  <p>this is login.php :</p>
  
  <pre><code>&lt;?php
  session_start();
  $pseudo = $_POST['pseudo'];
  $mail = $_POST['mail'];
  
  $pseudo=mysql_real_escape_string($pseudo);
  $pseudo=ltrim($pseudo);
  $pseudo=rtrim($pseudo);
  
  $mail=mysql_real_escape_string($mail);
  $mail=trim($mail);
  
  $sql=mysqli_connect('localhost','root','','bdd_name');
  $query=("SELECT COUNT(*) FROM t_people WHERE 'PEO_PSEUDO'='".$pseudo."' OR 'PEO_MAIL'='".$mail."'");
  $result = mysqli_prepare($sql,$query);
  
      mysqli_stmt_execute($result);
      mysqli_stmt_store_result($result);
  
  if (mysqli_stmt_num_rows($result) == 0) {
    echo 1;
   }
   else {
   echo 2;
   }
  mysqli_stmt_free_result($result);
  mysqli_stmt_close($result);
  ?&gt;
  </code></pre>
  
  <p>And this is a part of my JavaScript :</p>
  
  <pre><code>var pseudo=$("#pseudo").val();
  var mail=$("#mail").val();
      $.ajax({
          type: "POST",
          url: "login.php",
          data: {pseudo:pseudo, mail:mail}
          }).done(function(result) {
              if (result==1) {
                  good();
              }
              else if (result==2) {
                  bad();
              }
          });
  </code></pre>
  
  <p>Can anyone tell me what is wrong with this?</p>
  
  <p>I'm on this since hours now and I'm clueless...</p>