Php isset()函数无法正常工作

时间:2016-04-10 17:16:09

标签: php

我有一个用户提交的注册表。使用<?php if(isset($_POST['submit'])) { $f_name=$_POST['fname']; $l_name=$_POST['lname']; $email=$_POST['email']; $output_form= false; if(empty($f_name) && empty($email)) { echo 'please enter all the fields.<br />'; $output_form = true; } if(empty($f_name) && (! empty($email)) ) { echo 'please enter first name.<br />'; $output_form = true; } if((!empty($f_name)) && empty($email) ) { echo 'please enter E-Mail.<br />'; $output_form = true ; } if((!empty($f_name)) && (!e mpty($email)) ) { echo 'success.<br />'; $output_form= true; } } else $output_form = true; if ($output_form) { ?> <table border="0" align=center bgcolor=pink> <tr> <FORM NAME="form1" METHOD="POST" ACTION="<?php echo $_SERVER['PHP_SELF'];?>"> <td wedth='75' >first name:<INPUT TYPE="TEXT" VALUE="" NAME="fname"><br></td><br> <td wedth='75' >last name:<INPUT TYPE="TEXT" VALUE="" NAME="lname"><br></td><br> <td>e-mail:<INPUT TYPE="TEXT" VALUE="" NAME="email"><br></ td><br> <td><INPUT TYPE='submit' NAME='submit1' VALUE='submit'> </tr> </table> <?php } ?> 发送数据,以查看是否有任何内容放入表单输入框。如果没有,则将其发送给else,然后将其发送到函数,该函数将用户返回到注册表单以完成一些丢失的表单。由于某种原因,它无法正常工作。

这是我的支票代码:

{{1}}

1 个答案:

答案 0 :(得分:1)

我整理了你的php:

    <?php 
    if(isset($_POST['Submit'])){ 
        $f_name=$_POST['fname'];
        $l_name=$_POST['lname'];
        $email=$_POST['email'];
        $output_form= false;
        if(empty($f_name) && empty($email)){
            echo 'Please enter the fields<br/>';
            $output_form = true;
        } else {
            if(empty($f_name) && (!empty($email))){
                echo("Please enter first name <br/>");
                $output_form = true;
            } else {
                if(!empty($f_name) && (empty($email))){
                echo("Please enter your email");
                $output_form = true;    
                } else {
                    // You wouldnt really need an if statement here considering it went through all the possibilitys but just incase for security reasons Ill go ahead and make it
                    if(!empty($f_name) && (!empty($email))){
                        echo("Success<br/>");   
                    };
                };
            };
        };
?>

我还修复了你的HTML:

<html>
    <head>
        <!-- Meta Data and title and other stuff goes here -->
    </head>
    <body>
        <table border="0" align="center" bgcolor="pink">
            <tr>
                <form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>"> <!-- Im not sure what you were aiming for here wihh your action statement with your echoing but I left it alone -->
                    <td width="75">First name: <input type="text" name="fname"><br/></td>
                    <td width="75">last name: <input type="text"  name="lname"><br/></td>
                    <td width="75">Email: <input type="text" name="email"><br/></td>
                    <td><input type="submit" name="Submit"></input></td>
                </form>
            </tr>
        </table> 
    </body>
</html>