下午好!
我有一个HTML,PHP和MySQL的登录脚本,它工作正常,但我希望“登录”页面能够打印一条带有简单' p'的错误信息。当字段为空时。
我的login.php页面:
<form action="includes/loginprocess.php" method="POST">
<input type="text" name="user" placeholder="Username">
<input type="password"name="pass" placeholder="Password">
<input type="submit" value="Login">
</form>
loginprocess.php:
<?php
// Includes the database connection file.
include("mysqlconnection.php");
// Check if there was a POST or if some field are empty.
if (!empty($_POST) AND (empty($_POST['user']) OR empty($_POST['pass']))) {
header("Location: ../login.php"); exit;
}
//And a lot of other things come after...
我想知道的是,是否有任何方法可以使loginprocess.php在login.php中的输入上方回显一些简单的消息,如:
<form action="loginprocess.php" method="POST">
//This!!!
<p style="color:red;">Fields Empty!</p>
<input type="text" name="user" placeholder="Username">
<input type="password"name="pass" placeholder="Password">
<input type="submit" value="Login">
</form>
这对我很有帮助,谢谢你们。
答案 0 :(得分:0)
如果您只想验证输入是否为空,那么您应该根据需要标记输入并让html5验证器为您处理。
<form action="includes/loginprocess.php" method="POST">
<input type="text" name="user" placeholder="Username" required>
<input type="password"name="pass" placeholder="Password" required>
<input type="submit" value="Login">
</form>