You are trying to use mysql_query
when you have (based on the rest of your code that is working) a PDO
connection. Change your query to use your existing connection:
try {
$stmt = $db->prepare("SELECT COUNT(*) FROM users WHERE firstName = :sName");
$stmt->bindValue(':sName', $sName);
$stmt->execute();
$num_rows = $stmt->fetchColumn();
}
catch (PDOEXception $ex) {
echo $ex;
}
if ($num_rows > 0) {
echo 'User with this name already exists';
}
else {
// the rest of your code here