gpt4 book ai didi

PHP mySQL if 语句 - 检查电子邮件是否已经在数据库中

转载 作者:行者123 更新时间:2023-11-29 04:34:20 24 4
gpt4 key购买 nike

我有一个表格可以在我的网站上注册电子邮件。我正在尝试在 PHP 中创建一个检查,以首先确定电子邮件是否已经在数据库中注册,然后再允许用户再次注册。

IF 语句没有执行....我做错了什么? else 语句工作正常。

请注意 - db.php 文件包含连接设置 $conn。 else 语句将电子邮件地址放入数据库。

    <?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";


}
}

?>

最佳答案

只是你的 PHP 脚本有错别字,改一下

if(mysqli_num_rows($query>0))

进入

if(mysqli_num_rows($query) > 0)

关于PHP mySQL if 语句 - 检查电子邮件是否已经在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48043149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com