Advertisement
tamaro_skaljic

send_message.php

Jun 27th, 2021
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <?php
  2. // Message sending is only possible over HTTP POST and when the user is logged in
  3. require './includes/http_method_post.php';
  4. require './includes/logged_in.php';
  5.  
  6. // When a message was sent and it's not empty, insert it to the database with appropriate user information
  7. if($_POST['message'] != ''){
  8.     $query = "INSERT INTO public.chat_message (user_id, message) VALUES (:user_id, :message)";
  9.     $query_params = array(':user_id' => $_SESSION['user_id'], ':message' => $_POST['message']);
  10.     try{
  11.         $stmt = $pdo->prepare($query);
  12.         $result = $stmt->execute($query_params);
  13.     }
  14.     catch(PDOException $ex){
  15.         // Fail early when a error occurs
  16.         echo '<span style="color: red">ERROR! Code: 011</span>';
  17.         exit;
  18.     }
  19. }
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement