表单提交后,在PHP中重新加载页面

时间:2016-09-01 11:15:24

标签: javascript php

我有一个页面,我可以批准或删除用户在我的博客上提交的评论(我使用PHP和MySQL构建了没有Wordpress的博客)现在一切正常,我只需要一个问题的帮助。  我从一个页面删除和批准评论意味着我有单独的查询,但两者都在同一页面上,我想在提交表单后只自动刷新一次页面,下面是我的代码。  批准评论 -

 <?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>";
         }
     }

    ;?>

1 个答案:

答案 0 :(得分:0)

使用重定向('Location:the_same_page_name');

相关问题