我正在尝试创建一个注册页面,并且需要验证用户名和电子邮件是否已经退出。
如果我在两个查询中执行此操作,它可以正常工作,但切换到一个查询,则它无法正常工作,有时它不会验证值之一。
我尝试如下,但它不能正常工作,有时它不验证电子邮件或用户名:
$uname = $_POST['username'];
$email = $_POST['email'];
$sql = "SELECT uid FROM users WHERE username = :username OR email = :email";
$stmt1 = $pdo->prepare($sql);
$stmt1->bindParam(":username", $uname, PDO::PARAM_STR);
$stmt1->bindParam(":email", $email, PDO::PARAM_STR);
$stmt1->execute();
if($stmt1->rowCount() == 1){
$rows = $stmt1->fetch();
if($rows['username'] == 1){
$errors['username'] = "Username already in use.";
}else{
$username = $uname;
}
if($rows['email'] == 1){
$errors['email'] = "Email already in use.";
}else{
$email= $email;
}
}
unset($stmt1);
qq_笑_17
绝地无双