MYSQL Check if username already exists in database : <p>My code was working but after I inserted a query to check if the first name in MYSQL database already exists, it does not work anymore. Here you can see my code, if you have any tip on how to make this work, I will appreciate it. Thank you very much!</p>

<p>I have tried to work with mysql_num_rows command, but it seems like I didn't use it correctly. </p>

<pre><code>&lt;?php 

require_once __DIR__.'/connect.php';

$sName = $_POST['txtName'];

$query = mysql_query("SELECT * FROM users WHERE firstName = '$sName' ");
if (mysql_num_rows ($query) &gt; 0){
    echo 'User with this name already exists';
}else{
    try {
        $stmt = $db-&gt;prepare('INSERT INTO users
    VALUES (null, :sName, :sLastName, :sEmail, :sCountry )');
        $stmt-&gt;bindValue(':sName', $sName);

        $stmt-&gt;execute();
        echo 'New user was successfully inserted';
    } catch (PDOEXception $ex) {
        echo $ex;
    }
}
</code></pre>
