使用PHP在另一个HTML文件的特定行中回显HTML内容


Echo HTML content in specific line of another HTML file with PHP

下午好!

我有一个HTML、PHP和MySQL的登录脚本,它运行良好,但当字段为空时,我希望登录页面打印一条带有简单"p"的错误消息。

我的登录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>

这对我帮助很大,谢谢大家。

如果您只想让验证捕捉输入是否为空,那么您应该简单地将输入标记为所需,并让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>