我有一个表单可以在我的网站上注册电子邮件。我试图在PHP中创建一个检查,首先确定电子邮件是否已经在DB中注册,然后再允许用户再次注册。
IF声明没有执行....我做错了什么? else语句工作正常。
请注意 - db.php文件包含连接设置$ conn。 else语句将电子邮件地址放入db。
<?php
include_once 'db.php';
$fullname = $_POST['signup_name_of_user'];
$email = $_POST['signup_email_of_user'];
mysqli_select_db('database');
if(isset($_POST['signup_email_of_user']))
{
$checkdata = "SELECT signup_email_of_user FROM database WHERE signup_email_of_user = '$email'";
$query = mysqli_query($conn, $checkdata);
if(mysqli_num_rows($query>0))
{
echo "E-mail Already Exists. You cannot register more than twice!";
exit();
}
else {
$sql = "INSERT INTO database (signup_name_of_user, signup_email_of_user) VALUES ('$fullname', '$email')";
mysqli_query($conn, $sql);
echo "You have been successfully registered";
}
}
?>
&#13;
答案 0 :(得分:3)
您的PHP脚本中只有一个拼写错误,请更改
if(mysqli_num_rows($query>0))
向
if(mysqli_num_rows($query) > 0)
答案 1 :(得分:1)
{{1}} 会这样做的!