2016-09-01 136 views
-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>"; 
     } 
    } 

    ;?> 
+0

您想通過一次點擊同時刪除並確認評論嗎? –

+0

關閉PHP標籤前的';'是什麼? –

+0

@PatrickMlr一點都沒有,我有一個有兩個按鈕的表單,一個查詢可以一次性刪除或批准,具體取決於點擊哪個按鈕,我測試了代碼的功能並且工作正常,但是在顯示警告之後頁面沒有重新加載以上是代碼。 –

回答

0

使用重定向( '位置:the_same_page_name');

相關問題