【问题标题】:the email matching part is not working.电子邮件匹配部分不起作用。
【发布时间】:2018-08-24 00:52:38
【问题描述】:

我创建了一个使用 php 的注册表单,但是 邮件不匹配时代码不显示错误消息
我在 php 方面没有丰富的经验,可以使用一些帮助 $email 变量从用户那里获取电子邮件输入,而 $VerifyEmail 再次获取电子邮件输入以验证电子邮件,但检查电子邮件是否相同或不同时不起作用。

<?php 
    $con=mysqli_connect("localhost","root","","test");
    if(mysqli_connect_errno())
    {
        echo "there is an error".mysqli_connect_errno();
    }
        $username="";
        $firstname="";
        $email="";
        $email2="";
        $password="";
        $password2="";
        $date="";
    if(isset($_POST['submit_button']))
    {


        $username = strip_tags($_POST['username']); //Remove html tags
        $username = str_replace(' ', '', $username); //remove spaces
        $username = ucfirst(strtolower($username)); //Uppercase first letter


        //Last name
        $firstname = strip_tags($_POST['firstname']); //Remove html tags
        $firstname = str_replace(' ', '', $firstname); //remove spaces
        $firstname = ucfirst(strtolower($firstname)); //Uppercase first letter

        //email
        $Email = strip_tags($_POST['Email']); //Remove html tags
        $Email = str_replace(' ', '', $Email); //remove spaces
        $Email = ucfirst(strtolower($Email)); //Uppercase first letter


        //email 2
        $VerifyEmail = strip_tags($_POST['VerifyEmail']); //Remove html tags
        $VerifyEmail = str_replace(' ', '', $VerifyEmail); //remove spaces
        $VerifyEmail = ucfirst(strtolower($emVerifyEmail2)); //Uppercase first letter


        //Password
        $password = strip_tags($_POST['password']); //Remove html tags
        $password2 = strip_tags($_POST['verifypassword']); //Remove html tags
        $date=date(Y-m-d);


        if ($Email == $VerifyEmail) {
                if (filter_var($Email, FILTER_VALIDATE_EMAIL)) {
                $Email=filter_var($Email, FILTER_VALIDATE_EMAIL);
                }
                else 
                    {echo "Improper format";}
        }
        else {
            echo "emails do not match";
        }






    }
     ?>

    <!DOCTYPE html>
    <html>
    <head>
        <title>Sign up for Musings</title>
    </head>
    <body>
        <div id="SignupPart">
        <form action="regestration.php" type="POST">
            <h2>Signup</h2>
    <div>
            <label for="username">Username</label>
    <input type="text" name="username" id="username" placeholder="enter username" required> 
    </div>      

    <div>
            <label for="firstname">firstname</label>
    <input type="text" name="firstname" id="firstname" placeholder="enter firstname" required>  
    </div>


    <div>
            <label for="Email">Email</label>
    <input type="Email" name="Email" id="Email" placeholder="enter your Email" required>    
    </div>

    <div>
            <label for="VerifyEmail">enter Email again</label>
    <input type="Email" name="VerifyEmail" id="VerifyEmail" placeholder="enter your Email again" required>  
    </div>

    <div>
            <label for="password">enter password</label>
    <input type="password" name="password" id="password" placeholder="enter password" required> 
    </div>

    <div>
            <label for="verifypassword">enter password again</label>
    <input type="password" name="verifypassword" id="verifypassword" placeholder="enter password again" required>   
    </div>

    <input type="submit" name="submit_button" value="register">




        </form>
        </div>

    </body>
    </html>

【问题讨论】:

  • strtolower($emVerifyEmail2) 是什么? $emVerifyEmail2 值从何而来? PS你不应该过滤电子邮件输入,你应该只验证它,如果用户提供任何空格 - 例如 - 在那个输入中你应该返回一些错误消息而不是过滤输入
  • 第1步:将PHP错误报告配置为适合开发的级别,以便PHP可以自行提醒您此类错误。如果您不知道这意味着什么,请去研究/阅读。

标签: php html xampp


【解决方案1】:

请更改 $VerifyEmail = ucfirst(strtolower($emVerifyEmail2));

$VerifyEmail = ucfirst(strtolower($VerifyEmail));

【讨论】:

  • 即使在我输入两封不同的电子邮件时更正了变量,也没有显示错误消息
猜你喜欢
  • 1970-01-01
  • 2014-07-05
  • 2011-05-18
  • 2016-12-14
  • 2015-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多