duanpendan8067 2016-09-01 11:15
浏览 49

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

I have one page where i can Approve or Delete comments which user submitted on my blog (I built the blog without Wordpress with PHP and MySQL) Now everything is working fine and i just need help with one question. I'm deleting and approving comments from one page means i have separate queries but both are on same page and i want to auto-refresh page only once after submitting of form, below is code which i has. For approving comment -

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

for deleting comment

<?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条回答 默认 最新

  • duanfengshang1088 2016-09-01 11:43
    关注

    Use redirect('Location: the_same_page_name');

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据