title: Ajax : check email availability with PHP
body: <p>if I input an email that is not in the database, always the same alert with the alert if the email is in the database. What's wrong with my coding ?</p>
  
  <p><a href="https://i.stack.imgur.com/6nVjf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6nVjf.png" alt="enter image description here"></a></p>
  
  <p>I input email 'irsyadfahmy@gmail.com' and I enter the result instead 'Email Address can used' should 'Email Address Already in Use'.</p>
  
  <pre><code>    &lt;html&gt;
      &lt;head&gt;
      &lt;!-- sweet alert --&gt; 
          &lt;link rel="stylesheet" type="text/css" href="css/sweetalert.css"&gt;
          &lt;script type="text/javascript" src="js/sweetalert.min.js"&gt;&lt;/script&gt;
      &lt;!-- end sweet alert --&gt; 
      &lt;script type="text/javascript"&gt;
          $(document).ready(function(){
              $('#email').blur(function(){
                  var email = $(this).val();
                  $.ajax({
                      type    : 'POST',
                      url     : 'check-email.php',
                      data    : 'email='+email,
                      success : function(data){
                          if(data==0)
                          {
                          swal({
                              title: "Email Address can used",
                              text: "",
                              type: "success"
                          });     
                          }
                          else
                          {
                              swal({
                              title: "Email Address Already in Use",
                              text: "",
                              type: "warning"
                          }); 
                          }
                      },
                  });
              });
          });
              &lt;/script&gt;
      &lt;/head&gt;
  &lt;body&gt;
  &lt;form class="form-horizontal" method="POST" name="form"&gt;
  &lt;input type="email" name="email" id="email" class="form-control" required&gt;
  &lt;/form&gt;
  &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>check-email.php</p>
  
  <pre><code>&lt;?php
  include 'libraries/config.php';
  $email   = $_POST['email'];
  
  $cekdata=mysqli_query($conn,"SELECT * FROM user_csr WHERE email = '$email'");
  ?&gt;
  </code></pre>
  
  <p>result :
  <a href="https://i.stack.imgur.com/QefZN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QefZN.png" alt="enter image description here"></a></p>