title: Ajax check registered email on form
body: <p>I've taken this script to check if email is registered in DB using ajax. The problem is:
  It's just checking once, if user insert a registered email and then insert another email the var in checkemail.php do not change.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function() {
          var x_timer;    
          $("#email").keyup(function (e){
              clearTimeout(x_timer);
              var email = $(this).val();
              x_timer = setTimeout(function(){
                  check_username_ajax(email);
              }, 600);
          }); 
  
          function check_username_ajax(email){
              $.post('checkemail.php', {'email':email}, function(data) {
                  $("#user-result").html(data);
              });
          }
      });
  &lt;/script&gt;
  &lt;input type="email" name="email" id="email" placeholder="E-mail" /&gt;&lt;span id="user-result"&gt;&lt;/span&gt;
  </code></pre>
  
  <p>checkemail.php</p>
  
  <pre><code>&lt;?php
      require'conexao.php';
      $email = mysql_real_escape_string($_POST['email']);
      $SQL = "SELECT email FROM clients WHERE email = '" . $email . "'";
      $check = @mysql_query($SQL) or die("Erro no banco de dados!");
      $result = @mysql_num_rows($check);
  
      if($result){
          $emailstate = "1";
          echo '&lt;script type="text/javascript"&gt;alert("O E-mail informado já está cadastrado.");&lt;/script&gt;
          &lt;input type="radio" id="emailstate" name="emailstate" value="&lt;?php echo $emailstate; ?&gt;" style="display:none;" checked&gt;';
      } else {
          $emailstate = "0";
          echo '&lt;input type="radio" id="emailstate" name="emailstate" value="&lt;?php echo $emailstate; ?&gt;" style="display:none;" checked&gt;';
      }
  ?&gt;
  </code></pre>
  
  <p>Can someone help me please?</p>