Php 提交并刷新到主页后的消息
我希望在提交消息后出现,并在三秒后刷新到主页。需要一些建议来编写此代码 此处显示没有消息的主代码:Php 提交并刷新到主页后的消息,php,Php,我希望在提交消息后出现,并在三秒后刷新到主页。需要一些建议来编写此代码 此处显示没有消息的主代码: <!DOCTYPE html> <html> <meta http-equiv="content-type" content="text/html" /> <meta charset="utf-8" /> <?php require_once("db.inc.php"); ?> <link rel="stylesheet" ty
<!DOCTYPE html>
<html>
<meta http-equiv="content-type" content="text/html" />
<meta charset="utf-8" />
<?php
require_once("db.inc.php");
?>
<link rel="stylesheet" type="text/css" href="styles2.css" />
</head>
<body>
<?php
if(isset($_POST['selected_name'])){
$stmt = $mysqli->prepare("DELETE FROM artikel WHERE anr=?");
$stmt->bind_param('i', $_POST['selected_name']);
$stmt->execute();
$stmt->close();
if ()
}
?>
<form action="" method="POST">
<p>Artikel:
<?php
$stmt = $mysqli->prepare("SELECT anr, name FROM artikel");
$stmt->execute();
$stmt->bind_result($anr, $name);
echo "<select name='selected_name'><br />";
while ($stmt->fetch ()) {
echo '<option value='.$anr.'>'.$anr.' | '.$name.'</option>';
}
echo "</select>";
?>
<input type="submit" value="Datensatz löschen" />
</form>
</body>
</html>
阿蒂克尔:
对于我来说,不清楚如何对if条件进行编码,以便仅在提交后才显示消息。我的编码方式如下:
<?php
if(isset($_POST['selected_name'])){
$stmt = $mysqli->prepare("DELETE FROM artikel WHERE anr=?");
$stmt->bind_param('i', $_POST['selected_name']);
$stmt->execute();
$stmt->close();
echo "<h2>Artikel gelöscht</h2>";
}
header ("refresh:3; url=test.php");
?>
<form action="" method="POST">
<p>Artikel:
<?php
$stmt = $mysqli->prepare("SELECT anr, name FROM artikel");
$stmt->execute();
$stmt->bind_result($anr, $name);
echo "<select name='selected_name'><br />";
while ($stmt->fetch()) {
echo '<option value='.$anr.'>'.$anr.' | '.$name.'</option>';
}
echo "</select>";
?>
<input type="submit" name="submit" value="Datensatz löschen" />
</form>
</body>
</html>
阿蒂克尔:
但这样,消息不会消失,页面每三秒刷新一次,即使我不提交也可以使用元刷新方法。您可以阅读-即:
问题不在于刷新,而在于如何在提交消息后对消息进行编码您编写了“并在刷新主页3秒钟后”-因此,在代码成功执行后回显消息,并将元放在itI下回显消息,但在提交消息后仍保留在主页上,同样在复习之后,在你的问题中向我们展示你是如何做到这一点的。如果它不起作用,那么你很可能会有错误。