繁体   English   中英

如何检查我的数据库phpmyadmin中是否存在电子邮件

[英]How to check if email exists in my database phpmyadmin

我的register.php文件

我正在尝试检查在phpmyadmin上我的数据库中是否已经存在在表单输入中注册的电子邮件。 我如何才能做到这一点而又不破坏我的代码。

 <?php

    session_start();

    if( isset($_SESSION['user_id']) ){
        header("Location: index.php ");
    }

    require 'database.php';

    $message = '';

    if(!empty($_POST['email']) && !empty($_POST['password'])):

        // Enter the new user in the database

        $sql = "INSERT INTO signup (name, surname,email, password) VALUES (:name, :surname,:email, :password)";
        $stmt = $conn->prepare($sql);

        $stmt->bindParam(':name', $_POST['name']);
        $stmt->bindParam(':surname', $_POST['surname']);
        $stmt->bindParam(':email', $_POST['email']);
        $stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));

    if( $stmt->execute() ):
            $message = 'Successfully created new user';
        else:
            $message = 'Sorry there must have been an issue creating your account';
        endif;

    endif;

    ?>

这是一个使用PDO的函数,如果已经存在电子邮件,它将返回1:

 function check_mail_exist($con, $mail){
    $sql = $con->prepare("SELECT * FROM table_name WHERE column_mail='".$mail."'; ");
    $sql->execute();
    $result = $sql->rowCount();
    if ($result > 0)
        return 1;
    return 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM