电子邮件重复检查PHP与数据库

时间:2016-10-17 14:27:06

标签: php mysql

我检查重复的电子邮件时遇到小问题,我不知道我做错了什么。我可以通过POST从上一页获取键入的电子邮件地址,但不会readed query1($ sql1)。因此,如果我回显$ reg_num,它总是显示为'0',即使它正在使用mysql workbench。我在$ sql1或echo $ reg_num之前尝试过很多像echo $ emailAddress的东西....请帮帮我......

if(strpos($emailAddress, $emailValidCheck) === false) { 
    echo "<script> alert('Invalid email type. Use the correct email address.'); history.back(); </script>";
}

else {
    echo $emailAddress;

    $sql1="SELECT count(*) as count FROM peekachews.tbl_user WHERE user_email=".$emailAddress."";
    $result1=mysqli_query($conn, $sql1);  
    $row1=mysqli_fetch_assoc($result1); 
    $reg_num=$row1['count'];   

    if($reg_num > 0)
    {
        echo "<script> alert('Duplicated email.'); history.back(); </script>";
        die;
    }

    else if($reg_num = 0) {
        $sql2="insert into tbl_user (user_firstName, user_lastName, user_email, user_password, user_date) ";
        $sql2.="values ('$firstName', '$lastName', '$emailAddress', '$password', now() )";
        $result2=mysqli_query($conn, $sql2);
        //tot_row=mysql_affected_rows();
        mysqli_close($conn);

        echo "<script> alert('Congratulations on becoming a Peeknchews registered member.');
        location.replace('../php_login/login.php'); </script>";   
    }

}

2 个答案:

答案 0 :(得分:0)

您应该使用参数而不是仅仅将$emailaddress粘贴到$sql1字符串中。

如果您不想使用参数,只需在电子邮件地址的$sql1字符串中加上引号,如下所示:

$sql1="SELECT count(*) as count FROM peekachews.tbl_user WHERE user_email='$emailAddress'";

答案 1 :(得分:0)

解决。 我不知道为什么dot(。)是在sql语句中输入但完全是sql错误。

校正

$sql1="SELECT count(*) as count FROM peekachews.tbl_user WHERE user_email='$emailAddress'";