Verify e-mail is not already registered PHP Mysql
<p>Right now I am trying to set up a user registration page, and I've been having trouble with verifying that the e-mail is not already in use. I figured all I had to do was make a query to my database to check and see if the e-mail was already in use. This seems pretty straight forward, so I don't know why it's giving me such a problem. </p>

<p>I've read several posts, and tried several approaches with PDO and mysqli, but I have still yet to get this script to function properly. Any help would be greatly appreciated.</p>

<pre><code>&lt;?php
session_start();
if( isset($_SESSION['user_id']) ){
    header("Location: /");
}
require 'database.php';
$message = '';
if(!empty($_POST['email']) &amp;&amp; !empty($_POST['password'])&amp;&amp; !empty($_POST['firstname'])&amp;&amp; !empty($_POST['lastname'])&amp;&amp; !empty($_POST['phone'])&amp;&amp; !empty($_POST['address'])&amp;&amp; !empty($_POST['city'])&amp;&amp; !empty($_POST['zip'])):

//check to see if e-mail is already being used
    //This method always says that the email is already in use, even if I am entering a new one. 
    /*
    $records = $conn-&gt;prepare('SELECT * FROM users WHERE email = :email');
    $records-&gt;bindParam(':email', $_POST['email']);
    $records-&gt;execute();
    $results = $records-&gt;fetch(PDO::FETCH_ASSOC);
    if( count($results) &gt; 0){
        $message = "Sorry, that E-mail address is already registered to an account.";
    }
    */
    //this one never says that the email is in use.
    /*
    $email = $_POST['email'];
    $query = mysqli_query($conn, "SELECT * FROM users WHERE email='".$email."'");

    if(mysqli_num_rows($query) &gt; 0){
        $message = "Sorry, that E-mail address is already registered to an account.";
    }
    */

    //this was the last method I tried, and it also never says that the email is in use.
    try{
        $stmt2 = $conn-&gt;prepare('SELECT `email` FROM `user` WHERE email = ?');
        $stmt2-&gt;bindParam(1, $_POST['email']); 
        $stmt2-&gt;execute();
        while($row = $stmt2-&gt;fetch(PDO::FETCH_ASSOC)) {
        }
    }
    catch(PDOException $e){
        echo 'ERROR: ' . $e-&gt;getMessage();
    }

    if($stmt2-&gt;rowCount() &gt; 0){
        //echo "The record exists!";
        $message = "Sorry, that E-mail address is already registered to an account.";
    }

    else{
        // Enter the new user in the database
        $sql = "INSERT INTO users (email, password, firstname, lastname, phone, address, city, zip) VALUES (:email, :password, :firstname, :lastname, :phone, :address, :city, :zip)";
        $stmt = $conn-&gt;prepare($sql);

        $stmt-&gt;bindParam(':email', $_POST['email']);
        $stmt-&gt;bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
        $stmt-&gt;bindParam(':firstname', $_POST['firstname']);
        $stmt-&gt;bindParam(':lastname', $_POST['lastname']);
        $stmt-&gt;bindParam(':phone', $_POST['phone']);
        $stmt-&gt;bindParam(':address', $_POST['address']);
        $stmt-&gt;bindParam(':city', $_POST['city']);
        $stmt-&gt;bindParam(':zip', $_POST['zip']);

        if( $stmt-&gt;execute() ):
            $message = 'Successfully created new user';
        else:
            $message = 'Sorry there must have been an issue creating your account';
        endif;
    }

endif;

?&gt;
</code></pre>