I've been wondering how to check in a MySQL table if username and/or email are duplicates during registration. Here's what I've tried so far but to no avail:
$username = $_POST['username'];
$sq = $db->exec("SELECT * FROM `users` WHERE `username` = '$username'");
if ($sq->rowCount() > 0)
{
$msg = "That username is already taken.";
$error = true;
}
$email = $_POST['email'];
$sq = $db->exec("SELECT * FROM `users` WHERE `email` = '$email'");
if ($sq->rowCount > 0)
{
$msg = "That email is already taken.";
$error = true;
}
if (!error)
{
//add to db
}
The error this gives is Call to a member function rowCount() on a non-object
Could you please help?