PHP代码不在if语句中回显

时间:2015-02-21 19:25:21

标签: php

我有一个我建立的注册页面,如果我将一个字段留空,没有任何内容可以回复,告诉我它是空的,就像我的代码应该设置为。例如,如果我将用户名字段留空,那么它应该说“你不能将用户名字段留空”。谁能告诉我发生了什么事?

<?php
if(version_compare(PHP_VERSION, "5.2.0", ">")){

    include('config.php');



    if($_SERVER['REQUEST_METHOD'] == "POST"){
        if($_POST['user']==""){
            echo "You can't leave the username field empty.<br />";
            } elseif($_POST['password'] == ""){
                echo "You can't leave the password field empty.<br />";
            }elseif($_POST['confirm_password'] == ""){
                echo "You can't leave the confirmation password field empty.<br />";
                }elseif ($_POST['email'] == "" ){
                    echo "You can't leave the email field empty.<br />";
                }elseif($_POST['confirm_email'] == ""){
                    echo "YOu can't leave the confirmation email field empty.<br />";
                    }elseif($_POST['password'] != $_POST['confirm_password']){
                        echo "Password does not match.<br />";

                    }elseif($_POST['confirm_password'] != $_POST['password']){

                        echo "Password does not match.<br />";

                        }elseif($_POST['email'] != $_POST['confirm_email']){
                            echo "Email does not match";


                            }elseif($_POST['confrim_email'] != $_POST['email']){
                            echo "Email does not match";

                            }else{


                echo "Everything is correct and not empty.";

                }
        }else{





            ?><form action="" method"POST">
            <input type="text" name="user"><br />
             <input type="password" name="password"><br />
             <input type="password" name="confirm_password"><br />
             <input type="email" name="email"><br />
             <input type="email" name="confirm_email"><br />
            <button type="submit">Sign Up</button>
            </form><?php

        }
    }else{

        ?> Please update your Php Version to suit these code settings<?php

            }
        ?>

1 个答案:

答案 0 :(得分:0)

尝试使用@Feek指向的isset函数,以及empty ...

if(isset($_POST['user']) && empty($_POST['user'])){//set but empty
                echo "You can't leave the username field empty.<br />";
}

还要确保启用错误报告:

<?php
// Turn off error reporting
error_reporting(0);

// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Report all errors
error_reporting(E_ALL);

// Same as error_reporting(E_ALL);
ini_set("error_reporting", E_ALL);

// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>