title: How to separately check if PHP username or email exists in database
body: <p>Right now my code checks if both the username and email variables exist in the database because they are both unique keys, but how do I make it so I can check each one individually and output different responses?</p>
  
  <p>Such as if the username exists -> "That username already exists."
  Or if the email exists, but username does not -> "That email already exists."</p>
  
  <pre><code>&lt;?php
    include 'include/connection.php';
  
    $username = mysqli_real_escape_string($conn, $_REQUEST['username']);
    $password = mysqli_real_escape_string($conn, $_REQUEST['password']);
    $name = mysqli_real_escape_string($conn, $_REQUEST['name']);
    $email = mysqli_real_escape_string($conn, $_REQUEST['email']);
  
    $sql = "INSERT INTO userdata (username, password, name, email) VALUES ('$username', '$password', '$name', '$email')";
  
    if (mysqli_query($conn, $sql)) {
      echo "Your account was created successfully, please login to continue.";
      echo '&lt;form action="login.php"&gt;
              &lt;input type="submit" name="login" id="login" value="Login" /&gt;
            &lt;/form&gt;';
    } else {
      echo "That username already exists, please try again.";
      echo '&lt;form action="registration.php"&gt;
              &lt;input type="submit" name="register" id="register" value="Register" /&gt;
            &lt;/form&gt;';
    }
  ?&gt;
  </code></pre>