Php mysql检查电子邮件是否已在数据库中

问题描述 投票:-1回答:1

我正在尝试检查电子邮件是否已经存在于数据库中,但它无法正常工作。这是我尝试过的:我输入代码//电子邮件检查,以便您可以轻松找到它。

          <?php
    include('config.php');

    if(isset($_POST['register']))
    {


        $password= $_POST['password'];

        $en= md5($password);


        $sq ="INSERT INTO `user` (`id`, `name`, `age`, `email`, `password`, `course`, `referral`, `created_at`) VALUES (NULL, '".$_POST['name']."', '".$_POST['age']."', '".$_POST['email']."', '$en', '".$_POST['course']."', '".$_POST['referral']."', '".date("Y-m-d h:i:sa")."');";
        $qu =mysqli_query($conn,$sq);
        if($qu)
        {
            $sq ="SELECT * FROM `user` WHERE email='".$_POST['email']."' AND password='$en'";
            $qu =mysqli_query($conn,$sq);
            $newaccount=mysqli_fetch_array($qu);

            $referral = $_POST['referral'];
            if(!is_null($referral) && strlen($referral) > 0)
            {
                $referral = strtolower(str_replace(' ', '', $referral));

                $sql="SELECT * FROM `user`";
                $res=mysqli_query($conn,$sql);
                while($row = mysqli_fetch_assoc($res))
                {
                    $name = strtolower(str_replace(' ', '', $row['name']));
                    if($referral == $name)
                    {
// EMAIL CHECK
                        if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                            exit('Invalid email address');
                        }
                        $select = mysqli_query($connectionID, "SELECT `email` FROM `game` WHERE `email` = '".$_POST['email']."'") or exit(mysqli_error($connectionID));
                        if(mysqli_num_rows($select)) {
                            exit('This email is already being used');
                        }
                        $sq ="INSERT INTO `referral` (`id`, `user_id`, `sender_id`, `reward`, `status`, `created_at`, `id_course`, `id_content`) VALUES (NULL, '".$row['id']."', '".$newaccount['id']."', '10', '0', '".date("Y-m-d h:i:sa")."', '0', '0');";
                        $qu =mysqli_query($conn,$sq);
                        break;
                    }
                }
            }
            echo "<script>alert('Your Account Has Been Created')</script>";
                    echo "<script>window.open('page-login.php','_self')</script>";
        }
        else
        {
            echo "<script>alert('Your Account Has not  Been Created')</script>";
        }

    }

    ?>

我不确定我是否做了错误的安置或者什么,但一些帮助将不胜感激

php html
1个回答
1
投票
  • 您需要在数据库模式中将电子邮件设置为唯一
  • 因此,如果记录插入成功,则表示尚未存在
  • 如果错误,那么电子邮件已经存在。
© www.soinside.com 2019 - 2024. All rights reserved.