Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果mysqli数据库中已存在电子邮件,则阻止注册_Php_Email_Mysqli - Fatal编程技术网

Php 如果mysqli数据库中已存在电子邮件,则阻止注册

Php 如果mysqli数据库中已存在电子邮件,则阻止注册,php,email,mysqli,Php,Email,Mysqli,用户可以使用相同的电子邮件地址进行不同的注册 尝试使用Stack Overflow上的开发人员提供的不同解决方案,他们遇到了与我相同的问题,包括使emailUsers列成为数据库表中的唯一键,以及实现某种jQuery,但没有成功。我想问题是我丢失了一个重复电子邮件的“else-if”块,但是我尝试了各种各样的方法来实现它,它没有任何作用 <div id="signup"> <div class="container"> <div class=

用户可以使用相同的电子邮件地址进行不同的注册

尝试使用Stack Overflow上的开发人员提供的不同解决方案,他们遇到了与我相同的问题,包括使emailUsers列成为数据库表中的唯一键,以及实现某种jQuery,但没有成功。我想问题是我丢失了一个重复电子邮件的“else-if”块,但是我尝试了各种各样的方法来实现它,它没有任何作用

<div id="signup">
    <div class="container">
        <div class="row">
            <div class="col-sm-6 offset-sm-1">

                <div class="signup-left position-fixed text-center">

                    <img src="img/200.png">
                    <br><br><br>
                    <?php

                    if(isset($_GET['error']))
                    {
                        if($_GET['error'] == 'emptyfields')
                        {
                            echo '<div class="alert alert-danger" role="alert">
                                    <strong>Error: </strong> Fill In All The Fields
                                    </div>';
                        }
                        else if ($_GET['error'] == 'invalidmailuid')
                        {
                            echo '<div class="alert alert-danger" role="alert">
                                    <strong>Error: </strong> Please enter a valid email and user name
                                    </div>';
                        }
                        else if ($_GET['error'] == 'invalidmail')
                        {
                            echo '<div class="alert alert-danger" role="alert">
                                    <strong>Error: </strong> Please enter a valid email
                                    </div>';
                        }
                        else if ($_GET['error'] == 'invaliduid')
                        {
                            echo '<div class="alert alert-danger" role="alert">
                                    <strong>Error: </strong> Please enter a valid user name
                                    </div>';
                        }
                        else if ($_GET['error'] == 'passwordcheck')
                        {
                            echo '<div class="alert alert-danger" role="alert">
                                    <strong>Error: </strong> Passwords donot match
                                    </div>';
                        }
                        else if ($_GET['error'] == 'usertaken')
                        {
                            echo '<div class="alert alert-danger" role="alert">
                                    <strong>Error: </strong> This User name is already taken
                                    </div>';
                        }
                        else if ($_GET['error'] == 'invalidimagetype')
                        {
                            echo '<div class="alert alert-danger" role="alert">
                                    <strong>Error: </strong> Invalid image type 
                                    </div>';
                        }
                        else if ($_GET['error'] == 'imguploaderror')
                        {
                            echo '<div class="alert alert-danger" role="alert">
                                    <strong>Error: </strong> Image upload error, please try again
                                    </div>';
                        }
                        else if ($_GET['error'] == 'imgsizeexceeded')
                        {
                            echo '<div class="alert alert-danger" role="alert">
                                    <strong>Error: </strong> Image too large
                                    </div>';
                        }
                        else if ($_GET['error'] == 'sqlerror')
                        {
                            echo '<div class="alert alert-danger" role="alert">
                                    <strong>Website Error: </strong> Contact admin to have the issue fixed
                                    </div>';
                        }
                    }
                    else if (isset($_GET['signup']) == 'success')
                    {
                        echo '<div class="alert alert-success" role="alert">
                                <strong>Signup Successful</strong> Please Login from the login menu
                                </div>';
                    }
                ?>
        <form id="signup-form" action="includes/signup.inc.php" method='post' enctype="multipart/form-data">

            <input type="submit" class="btn btn-light btn-lg" name="signup-submit" value="Signup">

            <br><br>

            <a href="login.php">
                <i class="fa fa-sign-in fa-2x social-icon" aria-hidden="true"></i>
            </a>
            <a href="contact.php">
                <i class="fa fa-envelope fa-2x social-icon" aria-hidden="true"></i>
            </a>

    </div>

</div>






我希望能够阻止用户注册同一封电子邮件,并在用户尝试注册时生成错误消息


额外信息:可以发布我试图使emailUsers列成为唯一键的进一步详细方法,但当我这样做时,新用户无法再注册,即使他们使用不同的电子邮件。

使相关列唯一无疑是一种方法。没有任何理由会影响系统中还没有电子邮件的新用户。啊,是的。唯一的关键是工作。正确修改此列/数据库花了一段时间,但我最终设法使其正常工作。问题是,尽管由于修改了emailUsers UNIQUE KEY,数据库不会更新为重复的电子邮件,但用户仍然可以使用该电子邮件,并且他们仍然会收到一个提示,提示他们已注册,从而使他们相信自己已注册。如果电子邮件尚未保存,我仍然不知道如何创建一个提示,该提示将链接到emailUsers的唯一密钥。根据上面的代码,你有什么想法吗@Utkanosi如果我理解正确,MySQL正在阻止复制尝试,但是您的底层代码没有考虑来自MySQL的此类错误。您没有显示与数据库接口的实际PHP代码,但这基本上是您需要做的-倾听MySQL错误,并在如何响应用户时做出相应的反应。在过去几天中,我一直在试图找到解决此问题的方法,但仍然没有任何乐趣。是的,现在我在emailUsers列中启用了UNIQUE KEY,MySQL不会保存重复的电子邮件。没有生成任何错误。但是,即使数据库没有保存重复的电子邮件,用户也会收到一条提示,说明该用户已成功注册。如果您看到我在上面发表的原始帖子,如果该用户使用重复的电子邮件注册,则应该会生成错误。如果要查看,则错误为“usertake”。如果你想知道MySQL在尝试复制唯一密钥时没有产生错误,我可以发布更多的代码。至少,您应该能够通过检查
受影响的_行
stat来推断这一点-如果输入了一行,这将是1,如果没有输入,这将是0。