我一直想知道如果在注册期间用户名和/或电子邮件重复,如何签入 MySQL 表。这是我到目前为止尝试过但无济于事的方法:
$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
}
这给出的错误是Call to a member function rowCount() on a non-object
能否请你帮忙?