Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 提交并刷新到主页后的消息_Php - Fatal编程技术网

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下回显消息,但在提交消息后仍保留在主页上,同样在复习之后,在你的问题中向我们展示你是如何做到这一点的。如果它不起作用,那么你很可能会有错误。