即使声明了`name`并且正确,$ _POST也会返回空

时间:2016-02-03 13:43:03

标签: php

我在PHP中有一个基本的登录表单。所有输入名称都是正确的,并且还正确声明了类型。但是$_POST会因为任何未知原因而返回空白。

<form class="form-horizontal" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
    <span id="status"></span>
        <div class="form-group">
                <label for="userName">Username</label>
                        <div class="input-group">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                            <input type="text" name="username" required class="form-control col-xs-12" placeholder="Username">
                        </div>
        </div>
        <div class="form-group">
                        <label for="passWord">Password</label>
                        <div class="input-group">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                            <input type="password" name="password" required class="form-control col-xs-12" placeholder="Password">
                        </div>
        </div>

    <input type="submit" name="submit" value="Login" class="btn btn-primary btn-block">
    <button type="reset" value="reset" class="btn btn-danger btn-block">Clear</button>
</form>

主脚本

$username = sanitizeString($_POST["username"]);
$password = sanitizeString($_POST["password"]);

sanitizeString功能只会删除非法行为。

请帮助我,因为我已经在这里待了好几个小时了。感谢

1 个答案:

答案 0 :(得分:0)

尝试添加所有inputid参数,例如:

<input type="text" id="username" name="username" required class="form-control col-xs-12" placeholder="Username">

更新:

<form class="form-horizontal" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">

按路径替换<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>,例如:myphp.php