title: Check row exists with PDO
body: <p>I cannot figure this out, I've been reading numerous Stack overflow threads and I keep getting an issue,</p>
  
  <p>right now if the user types anything, regardless if it is the same username or email, it would come up with an error. Please help!</p>
  
  <p>I want the error message to appear when the user types an username or email that is already on the database.</p>
  
  <pre><code>$sql = "SELECT count(*) FROM users WHERE user_email = :email OR user_name = :username";
          $query1 = $DBH-&gt;prepare($sql);
          $query1-&gt;execute(array(':username'  =&gt; $username,':email' =&gt; $email));
  
          if ($query1-&gt;rowCount() &gt; 0){
              // User Exists
              $error = "Username or E-Mail in Use";
  
          }   else{
              // User Does Not Exist
              //No errors - let’s create the account
              //Encrypt the password with a salt
              $encryptedPass = password_hash($_POST['password'], PASSWORD_DEFAULT);
              //Insert DB
              $query = "INSERT INTO users (user_email, user_password, user_forename, user_lastname, user_name, user_gender, user_country, user_number) VALUES (:email, :password, :firstname, :lastname, :username, :gender, :country, :mobile)";
              $result = $DBH-&gt;prepare($query);
              $result-&gt;bindParam(':username', $_POST['username']);
              $result-&gt;bindParam(':firstname', $_POST['firstname']);
              $result-&gt;bindParam(':lastname', $_POST['lastname']);
              $result-&gt;bindParam(':email', $_POST['email']);
              $result-&gt;bindParam(':gender', $_POST['gender']);
              $result-&gt;bindParam(':country', $_POST['country']);
              $result-&gt;bindParam(':mobile', $_POST['mobile']);
              $result-&gt;bindParam(':password', $encryptedPass);
  
              if($result-&gt;execute()){
                  echo '&lt;div class="alert alert-success" role="alert"&gt;Registration Successful!&lt;/div&gt;';
                  echo "&lt;script&gt; window.location.assign('index.php?p=login'); &lt;/script&gt;";
              }
          }
  </code></pre>
  
  <p>EDIT</p>
  
  <pre><code>        $stmt = $DBH-&gt;prepare("SELECT COUNT(*) FROM users WHERE user_email = :email OR user_name = :username");
          $stmt-&gt;execute(array(':username'  =&gt; $username,':email' =&gt; $email));
          $count = $stmt-&gt;fetchColumn();
  
          var_dump($count);
  
          if ($count &gt; 0) {
              $error1 = "Username or E-Mail in Use. Please try another.";
          }
  
          if(!$error){
  
                  //No errors - let’s create the account
                  //Encrypt the password with a salt
                  $encryptedPass = password_hash($_POST['password'], PASSWORD_DEFAULT);
                  //Insert DB
                  $query = "INSERT INTO users (user_email, user_password, user_forename, user_lastname, user_name, user_gender, user_country, user_number) VALUES (:email, :password, :firstname, :lastname, :username, :gender, :country, :mobile)";
                  $result = $DBH-&gt;prepare($query);
                  $result-&gt;bindParam(':username', $_POST['username']);
                  $result-&gt;bindParam(':firstname', $_POST['firstname']);
                  $result-&gt;bindParam(':lastname', $_POST['lastname']);
                  $result-&gt;bindParam(':email', $_POST['email']);
                  $result-&gt;bindParam(':gender', $_POST['gender']);
                  $result-&gt;bindParam(':country', $_POST['country']);
                  $result-&gt;bindParam(':mobile', $_POST['mobile']);
                  $result-&gt;bindParam(':password', $encryptedPass);
  
                  if($result-&gt;execute()){
                      echo '&lt;div class="alert alert-success" role="alert"&gt;Registration Successful!&lt;/div&gt;';
                      // echo "&lt;script&gt; window.location.assign('index.php?p=login'); &lt;/script&gt;";
                  }
              }
  </code></pre>
  
  <p>var dump = string(1) "0"</p>