我想在输入字段旁边显示 php 错误消息。我该怎么做?
这是我在同一页面上的 php 和 html 代码..这只是简单的测试代码..任何帮助都会很棒
尝试将 php 放在输入旁边,但这不起作用..相反我把它放在一个值中
<?php
if ( isset( $_POST['submit'] ) ) {
$mysqli = new mysqli("localhost", "root", "", "test");
$fname = $_POST["fname"];
$lname = $_POST["lname"];
if (empty($henny)) { $errorhenny = '<div class="isa_error">Frist name is required<br></div>'; }
if (empty($lname)) {
echo '<div class="isa_error">Last name is required<br></div>';
}
else{
$stmt = $mysqli->prepare("INSERT INTO test (Firstname, Lastname) VALUES (?, ?)");
$stmt->bind_param("ss", $fname, $lname);
$stmt->execute();
$stmt->close();
$mysqli->close();
}
}
?>
<html>
<body>
<form action="" method="post">
<input type="text" name="fname" value= "<?php echo $errorhenny; ?>">
<input type="text" name="lname">
<input type="submit" name="submit" value="Submit">
</form>
</html>