我在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
功能只会删除非法行为。
请帮助我,因为我已经在这里待了好几个小时了。感谢
答案 0 :(得分:0)
尝试添加所有input
,id
参数,例如:
<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