我正在验证电子邮件是否已经存在但由于此问题而无法执行此操作,我的查询返回false,空查询。请更正我的MySQL查询。
我得到的错误是:
mysql_num_rows期望参数1为资源布尔值
请参阅我的代码
$dup_email_check="SELECT email from users where 'email'='$email'";
$result = mysqli_query($conn,$dup_email_check);
if (mysql_num_rows($result) > 1){
echo "<script>alert('Email Already Exists')</script)";
}
else{
$query = "INSERT INTO users (`user_name`, `First_Name`, `Last_Name`, `Pass`, `Retype-pass`, `email`) VALUES ('$user_name','$first_name','$last_name','$pass','$retype_pass','$email')";
}
答案 0 :(得分:1)
这应该是
$dup-email-check
更改为
$dup_email_check
代码是
$dup_email="SELECT email from users where email= '$email'";
$result = mysqli_query($conn,$dup_email);
$count = count($result);
if($count >1){
echo "<script>alert('Email Already Exists')</script)";
}
else{
$query = "INSERT INTO users (`user_name`, `First_Name`, `Last_Name`, `Pass`, `Retype-pass`, `email`) VALUES ('$user_name','$first_name','$last_name','$pass','$retype_pass','$email')";
}
答案 1 :(得分:0)
您混合了mysql
和mysqli
if (mysqli_num_rows($result) > 1){
^// this shud be mysqli
echo "<script>alert('Email Already Exists')</script)";
}
else{
...