简体   繁体   English

为什么这个简单的注册页面不起作用?

[英]Why isn't this simple sign up page working?

I'm not sure why this isn't working, It is giving me no errors, but it won't display the results. 我不确定为什么这行不通,它没有给我任何错误,但不会显示结果。 I just want to display the results of the 3 text fields. 我只想显示3个文本字段的结果。 The next step I want to go about doing is entering the data into a database, then displaying it, but I guess that will come next. 我要做的下一步是将数据输入数据库,然后显示它,但是我想接下来会发生。 Thank you. 谢谢。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php
$Fname = $_POST["Fname"];
$Lname = $_POST["Lname"];
$Pword = $_POST["Pword"];

if (!isset($_POST['submit'])) { // if page is not

?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<form method = "post" action = "<?php echo $PHP_SELF;?>">

First name<input name="Fname" type="text" maxlength="12"
/>
<br />
<br />

Last name<input name="Lname" type="text" maxlength="12"
/>
<br />
<br />

<!--Address <input name="register_address" type="text" maxlength="12"
/>
<br />
 <br />-->
<!--<select name="state" value="State"></select>-->


Password<input name="Pword" type="text" maxlength="12"
/>
<br />
<br />

<!--Re-type Password<input name="register_password_confirm" type="text" maxlength="12"
/>
<br />
<br />-->

<input name="submit" type="button" value="Submit" />



</form>

<?
} else {
echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "Your Password is, " .$Pword.".<br />";
}
?>




</body>
</html>

Three issues I see 我看到的三个问题

1 - Your button is not a submit button 1-您的按钮不是“提交”按钮

Change: 更改:

<input name="submit" type="button" value="Submit" />

to

<input name="submit" type="submit" value="Submit" />

2 - Register globals may be turned off 2-寄存器全局变量可能已关闭

Change: 更改:

<?php echo $PHP_SELF;?>

to

<?php echo $_SERVER['PHP_SELF'];?>

3 - Short open tags may be turned off 3-短开放标签可能已关闭

Change: 更改:

<?
} else {
echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "Your Password is, " .$Pword.".<br />";
}
?>

to

<?php
} else {
echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "Your Password is, " .$Pword.".<br />";
}
?>

Your submit button needs to be changed to type="submit" , also you might want to move your variable declarations within the else statement to avoid PHP warnings: 您的提交按钮需要更改为type="submit" ,您也可能希望在else语句中移动变量声明,以避免PHP警告:

<input name="submit" type="submit" value="Submit" />

and: 和:

<?php
} else {
    $Fname = $_POST["Fname"];
    $Lname = $_POST["Lname"];
    $Pword = $_POST["Pword"];
    echo "Hello, ".$Fname." ".$Lname.".<br />";
    echo "Your Password is, " .$Pword.".<br />";
}
?>

Lastly, I would reduce the amount of html you put it the if statement to the bare minimum, this could cause conflicts if you change how the condition is handled in the future: 最后,我将把if语句放到最低限度的html数量减少了, if将来更改条件的处理方式,则可能导致冲突:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Untitled Document</title>
    </head>
    <body>

    <?php
    if (!isset($_POST['submit'])) { // if page is not
        ?>
        <form method = "post" action = "<?php echo $_SERVER['PHP_SELF'];?>">
            First name<input name="Fname" type="text" maxlength="12" /><br /><br />
            Last name<input name="Lname" type="text" maxlength="12" /><br /><br />
            <!--Address <input name="register_address" type="text" maxlength="12" /> <br /> <br />-->
            <!--<select name="state" value="State"></select>-->
            Password<input name="Pword" type="text" maxlength="12" /><br /><br />
            <!--Re-type Password<input name="register_password_confirm" type="text" maxlength="12" /><br /><br />-->
            <input name="submit" type="submit" value="Submit" />
        </form>
        <?php
    } else {
        $Fname = $_POST["Fname"];
        $Lname = $_POST["Lname"];
        $Pword = $_POST["Pword"];
        echo "Hello, ".$Fname." ".$Lname.".<br />";
        echo "Your Password is, " .$Pword.".<br />";
    }
    ?>
    </body>
</html>

Try adding a 尝试添加一个

<input type="hidden" name="submitted" value="1" />

and checking for 并检查

$_POST['submitted'] == 1

try echoing the result like this: 尝试回显如下结果:

echo "Hello, $Fname $Lname.<br />
      Your Password is, $Pword.<br />";

I forgot to add that you don't need the dots after variables when echoing using double quotations. 我忘了补充一点,当使用双引号进行回显时,您不需要在变量后面加点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM