-1
我有一个页面,我可以批准或删除用户在我的博客上提交的评论(我建立的博客没有Wordpress与PHP和MySQL)现在一切工作正常,我只需要帮助一个问题。 我正在删除和批准来自一个页面的评论意味着我有单独的查询,但都在同一页面上,我想只在提交表单后自动刷新一次页面,下面是我有的代码。 审批评论 -在表单提交后在PHP中重新加载页面
<?php
if(isset($_POST['approve_cmt'])) {
$id = $_POST['id'];
$sql = "UPDATE `blog_comments` SET `status` = '1' WHERE comment_id = '$id'";
$res = mysql_query($sql) or die(mysql_error());
if ($res == 1) {
echo "<script type='text/javascript'>alert('Comment approved!') window.location.reload(); </script>";
} else {
echo "<script type='text/javascript'>alert('Failed to approve comment') window.location.reload(); </script>";
}
}
;?>
删除评论
<?php
if(isset($_POST['delete_cmt'])) {
$id = $_POST['id'];
$sql = "DELETE FROM `blog_comments` WHERE `comment_id` = '$id'";
$res = mysql_query($sql) or die(mysql_error());
if ($res == 1) {
echo "<script type='text/javascript'>alert('comment deleted') window.location.reload(); </script>";
} else {
echo "<script type='text/javascript'>alert('unable to delete comment') window.location.reload(); </script>";
}
}
;?>
您想通过一次点击同时删除并确认评论吗? –
关闭PHP标签前的';'是什么? –
@PatrickMlr一点都没有,我有一个有两个按钮的表单,一个查询可以一次性删除或批准,具体取决于点击哪个按钮,我测试了代码的功能并且工作正常,但是在显示警告之后页面没有重新加载以上是代码。 –