title: Receiving multiple data through AJAX in PHP?
body: <p>I am working on a login form, where user types in his email, which is validated through AJAX and after that the password is verified through AJAX as well.
  Here is the code,
  JS code-</p>
  
  <pre><code>//AJAX for email input field
  function emailCheck(email) {
      return $.ajax({
          type: "POST",
          url: "ajax_index.php",
          data: "email=" + email
      });
  }
  
  //AJAX for password input field
  function passwordCheck(password, email) {
      return $.ajax({
          type: "POST",
          url: "ajax_index.php",
          data: {password: password, email: email}
      });
  }
  </code></pre>
  
  <p>PHP code - </p>
  
  <pre><code>//receives POST request from email field
  if (isset($_POST['email'])) {
      $email = mysqli_real_escape_string($dbconn, $_POST['email']);
  
      if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
          echo -1;
      } else {
          $query = "SELECT * from users WHERE email = '$email'";
          $query_result = mysqli_query($dbconn, $query) or die(mysqli_error($dbconn));
          $result_rows = mysqli_num_rows($query_result);
  
          echo $result_rows;
      }
  }
  
  //receives POST from password field
  if (isset($_POST['password'], $_POST['email'])) {
      $email = mysqli_real_escape_string($dbconn, $_POST['email']);
      $password = mysqli_real_escape_string($dbconn, $_POST['password']);
  
      $query = "SELECT email, password from users WHERE email = '$email'";
      $query_result = mysqli_query($dbconn, $query) or die(mysqli_error($dbconn));
      $result_rows = mysqli_num_rows($query_result);
  
      $row = mysqli_fetch_assoc($query_result);
  
      if (password_verify($password, $row['password'])) {
          echo 1;
      }
      else {
          echo 0;
      }
  }
  </code></pre>
  
  <p>As you can see, for the password field, I have to get both the <code>$_POST['password']</code> and <code>$_POST['email']</code>, so that I can verify the password against that email. But this invokes both handlers, the one for only email field and the one for both email and password which the one I only want to run. So, how I can solve this problem?
  Thank you.</p>