提交并刷新到主页后的消息

时间:2016-06-27 14:20:48

标签: 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" 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条件进行编码,以便仅在提交后才显示该消息。

1 个答案:

答案 0 :(得分:0)

我这样编码:

<?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>

但是这样一来,即使我没有提交,该消息也不会消失,页面每三秒刷新一次