PHP没有显示正确的消息

时间:2014-08-16 18:23:08

标签: php

我写的方式与其他方式有点不同,当提交html5表单时,我尝试将html5数据存储为php文件中的全局变量。

我通过填写html5中的所有表单来测试我的PHP脚本,但故意制作用户名密码并确认密码相同。它应该在else {}下显示退出消息;不知何故,它继续显示"请填写所有字段" 。我的错误在哪里?当然我做错了。

我使用了select for Gender,因为如果我使用了一个无线电标签,并且用户没有选择一个值(值=""),则会弹出未定义的索引错误。

这是HTML5                     

                            <p>
                                <label for="Username">Username</label>
                                <br />
                                <input id="Username" name="Username" type="text" size="20" required />
                            </p>
                            <br />
                            <p>
                                <label for="Password">Password</label>
                                <br />
                                <input id="Password" name="Password" type="password" size="20" required />
                            </p>
                            <br />
                            <p>
                                <label for="ConfirmPassword">Confirm Password</label>
                                <br />
                                <input id="ConfirmPassword" name="ConfirmPassword" type="password" size="20" required />
                            </p>
                            <br />



                            <p>
                                <label for="Name">Display Name</label>
                                <br />
                                <input id="Name" name="Name" type="text" placeholder="Name" size="25" required />
                            </p>
                            <br />
                            <p>
                                <label>Question</label>
                                <br />
                                    <select name="Question" required>
                                        <option value="" selected>Select a question</option>
                                        <option value="What is your mother's full name ?">What is your mother's full name ?</option>
                                        <option value="What is your nickname ?">What is your nickname ?</option>
                                        <option value="What is your first pet's name ?">What is your first pet's name ?</option>
                                        <option value="What is your favourite car ?">What is your favourite car ?</option>
                                        <option value="What is the name of the person you first kissed ?">What is the name of the person you first kissed ?</option>
                                        <option value="What is the name of the teacher who gave you your first failing grade ?">What is the name of the teacher who gave you your first failing grade ?</option>
                                    </select>
                            </p>
                            <br />
                            <p>
                                <label for="Answer">Answer</label>
                                <br />
                                <input id="Answer" name="Answer" type="text" placeholder="Answer to your question" size="50" required />
                            </p>
                            <br />
                            <br />
                            <p>
                                <label>Gender</label>
                                <br />
                                    <select name="Gender" required>
                                        <option value="" selected>Select a Gender</option>
                                        <option value="Male">Male</option>
                                        <option value="Female">Female</option>
                                    </select>
                            </p>

PHP就在这里

 <?php


$Username = $_POST[ "Username" ] ;
$Password = $_POST[ "Password" ] ;
$ConfirmPassword = $_POST[ "ConfirmPassword" ] ;
$Name = $_POST[ "Name" ] ;
$Question = $_POST[ "Question" ] ;
$Answer = $_POST[ "Answer" ] ;
$Gender = $_POST[ "Gender" ] ;


VerifyRegistrationForm() ;


function VerifyRegistrationForm()
{
    if ( empty ( $Username ) == True || empty ( $Password ) == True || empty ( $ConfirmPassword ) == True || empty ( $Name ) == True ||  empty ( $Question ) == True || empty ( $Answer ) == True || empty ( $Gender ) == True )
    {
        exit ( " Please fill in all the fields . " ) ;
    }
    else
    {
        if ( strlen ( $Username ) > 50 )
        {
            exit ( " \" Username \" exceeds maximum length . " ) ;
        }

        if ( strlen ( $Password ) > 50 )
        {
            exit ( " \" Password \" exceeds maximum length . " ) ;
        }

        if ( $Username == $Password )
        {
            exit ( " \" Username \" and \" Password \" must not be the same . " ) ;
        }

        if ( $ConfirmPassword != $Password )
        {
            exit ( " \" Password \" is invalid . " ) ;
        }
    }

}

0 个答案:

没有答案