Advertisement
tamaro_skaljic

delete_or_restore_message.php

Jun 27th, 2021
1,170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2. // If the user is an administrator
  3. if($_SESSION['is_admin']){
  4.     // And the user want to delete or restore a message
  5.     if(isset($_GET['delete']) or isset($_GET['restore'])){
  6.         // Delete the message associated with the GET parameter "delete"
  7.         if(isset($_GET['delete'])){
  8.             $query = "UPDATE public.chat_message SET deleted = TRUE WHERE message_id = :message_id";
  9.             $query_params = array(':message_id' => $_GET['delete']);
  10.         }
  11.         if(isset($_GET['restore'])){
  12.             // Restore the message associated with the GET parameter "restore"
  13.             $query = "UPDATE public.chat_message SET deleted = FALSE WHERE message_id = :message_id";
  14.             $query_params = array(':message_id' => $_GET['restore']);
  15.         }
  16.         try{
  17.             $stmt = $pdo->prepare($query);
  18.             $result = $stmt->execute($query_params);
  19.         }catch(PDOException $ex){
  20.             // If an unknown error occurred during restore or delete fail early
  21.             echo '<span style="color: red">ERROR! Code: 008</span>';
  22.             exit;
  23.         }
  24.     }
  25. }
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement