我希望在成功删除字段时显示成功消息。
我已经有一个确认警报正在运行,但现在我想回复一条消息(或用js显示它)查询成功了。
当我尝试if部分时,它总是显示post verwijdert(在荷兰语中删除的帖子),但我希望它在确认提醒后显示。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Verwijderen</title>
<header><link rel="stylesheet" type="text/css" href="../css/style.css">
<script language="JavaScript" type="text/javascript">
function delpage(id, title)
{
if (confirm("Weet je zeker dat je '" + title + "' wilt verwijderen?"))
{
window.location.href = '?delpage=' + id;
}
}
</script>
</header>
<body>
<nav>
<ul>
<li><a href="../index.php" target=_blank"">Bekijk site</a></li>
<li><a href="voegtoe.php">Toevoegen</a></li>
<li><a href="verwijder.php">Verwijderen</a></li>
<li><a href="?logout">Uitloggen</a></li>
</ul>
</nav>
</body>
</html>
<div id="verwijder">
<?php
include '../includes/includes.php';
$blogPosts = GetBlogPosts();
foreach ($blogPosts as $post)
{
}
//run if a page deletion has been requested
if(isset($_GET['delpage'])){
$delpage = $_GET['delpage'];
$delpage = mysql_real_escape_string($delpage);
$sql1 = mysql_query("DELETE FROM blog_posts WHERE id = '$delpage'");
header('Location:verwijder.php');
exit();
}
$sql = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");
while($row = mysql_fetch_object($sql))
{
echo "<tr>";
echo "<h1><td>$row->title</td></h1>";
if($row->id == 0)
{ //home page verberg delete link
}
else
{
// delete functie waarbij een alert word weergegeven of je dit zeker wil
echo "<td><a class='link' href=\"javascript:delpage('$row->id','$row->title');\">Verwijder</a></td>";
}
echo "</tr>";
}
if ($sql1 == !false)
{
echo '<h1>Post verwijdert</h1>';
}
else
{
echo 'test';
}
?>
</div>
答案 0 :(得分:0)
您可以在$_SESSION
中保留删除结果并执行以下操作。但在使用sessiony之前,请务必执行session_start();
//run if a page deletion has been requested
if(isset($_GET['delpage'])){
$delpage = $_GET['delpage'];
$delpage = mysql_real_escape_string($delpage);
$sql1 = mysql_query("DELETE FROM blog_posts WHERE id = '$delpage'");
if($sql1)
$_SESSION['delete'] = 1;
header('Location:verwijder.php');
exit();
}
然后在verwijder.php
if(isset($_SESSION['delete']) && $_SESSION['delete']){
//Show success message of delete here
unset($_SESSION['delete']);
}