title: Check if email exist using ajax
body: <p>Basically, I want to check if the email exists in the DB automatically. The function will not work when <code>connection.php</code> &amp; <code>mysqli</code> queries was inserted.</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;input type="email" name="email" class="formEmail"&gt;
  </code></pre>
  
  <p><strong>JS:</strong> </p>
  
  <pre><code>  $( document ).ready(function() {
      $('.formEmail').on('change', function() {
          //ajax request
          $.ajax({
              url: "queries/checkEmail.php",
              data: {
                  'email' : $('.formEmail').val()
              },
              dataType: 'json',
              success: function(data) {
                  if(date == true) {
                      alert('Email exists!');
                  }
                  else {
                      alert('Email doesnt!');
                  }
              },
              error: function(data){
                  //error
              }
          });
      });
    });
  </code></pre>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>require_once("../connection.php");
  
  $userEmail = $_GET['email'];
  
  $checkEmail=mysqli_query($con, "SELECT email from accounts WHERE email='$userEmail'");
  
  if (mysqli_num_rows($checkEmail) == 1) {
    $response = true;
  } else {
    $response = false;
  }
  
  echo json_encode($response);
  </code></pre>