电子邮件匹配部分无法正常工作。

时间:2018-03-15 09:24:52

标签: php html xampp

我使用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>

1 个答案:

答案 0 :(得分:0)

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

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