title: how to get two separate error results in a single query
body: <p>trying to make basic user registration script with PDO, when user and email exists i get single error message (user or email already exists), what im trying to get separate output for user and email errors. Also any other suggestions about this script much appreciated</p>
  
  <pre><code>if(isset($_POST['Register'])){
  $username = $_POST['username'];
  $email = $_POST['email'];
  $password = $_POST['password'];
  //Validating ???
  
  
  $statement  = $conn-&gt;prepare("SELECT COUNT(*) AS count FROM users 
      WHERE username = :username AND email = :email");
  $statement-&gt;bindParam(':username', $username);
  $statement-&gt;bindParam(':email', $email);
  $statement-&gt;execute(array(':username' =&gt; $username, ':email' =&gt; $email));
  
      while ($row = $statement -&gt;fetch(PDO::FETCH_ASSOC)) {
        $result = $row["count"];
          }
          if ($result &gt; 0) {
              echo "That usernam or email is already taken";
  
              }
          else {
              $sql = ("INSERT INTO users(username, email, password) VALUES(?, ?, ?)");
              $statement = $conn-&gt;prepare($sql);
              $statement-&gt;bindValue(":username", $username, PDO::PARAM_STR);
              $statement-&gt;bindValue(":password", $password, PDO::PARAM_STR);
              $statement-&gt;bindValue(":email", $email, PDO::PARAM_STR);
              $statement-&gt;execute(array("$username", "$email", "$password"));
              echo "New record created successfully";
              }
  }
  </code></pre>