无法打印表单数据 - 空白字段

时间:2014-06-10 19:43:00

标签: php html

我正在尝试在php中打印出登录框的值,但值始终显示为空。如果我为echo添加一个显式值,它就可以工作。请有人可以告诉我我可能做错了什么。感谢

<form name="login-form" class="login-form" action="index.php" method="post">

    <!--HEADER-->
    <div class="header">
    <!--TITLE--><h1>Client Portal Login</h1><!--END TITLE-->
    <!--DESCRIPTION--><span>Please login to your client portal</span><!--END DESCRIPTION-->
    </div>
    <!--END HEADER-->

    <!--CONTENT-->
    <div class="content">
    <!--USERNAME--><input name="username" type="text" class="input username" value="Username" onfocus="this.value=''" /><!--END USERNAME-->
    <!--PASSWORD--><input name="password" type="password" class="input password" value="Password" onfocus="this.value=''" /><!--END PASSWORD-->
    </div>
    <!--END CONTENT-->

    <!--FOOTER-->
    <div class="footer">
    <!--LOGIN BUTTON--><input type="submit" name="submit" value="Login" class="button" /><!--END LOGIN BUTTON-->
    <!--REGISTER BUTTON--><input type="submit" name="submit" value="Register" class="register" /><!--END REGISTER BUTTON-->
    </div>
    <!--END FOOTER-->

</form>

<?php
if(isset($_POST['submit'])){
    $username=$POST["username"];
    $password=$POST["password"];

echo $username . " " . $password;
}

?>

1 个答案:

答案 0 :(得分:0)

你输了一个错字。你需要$ _POST,而不是$ POST

http://www.php.net//manual/en/reserved.variables.post.php

编辑:另外,请考虑清理$ _POST数据:

Do htmlspecialchars and mysql_real_escape_string keep my PHP code safe from injection?