Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Message sending is only possible over HTTP POST and when the user is logged in
- require './includes/http_method_post.php';
- require './includes/logged_in.php';
- // When a message was sent and it's not empty, insert it to the database with appropriate user information
- if($_POST['message'] != ''){
- $query = "INSERT INTO public.chat_message (user_id, message) VALUES (:user_id, :message)";
- $query_params = array(':user_id' => $_SESSION['user_id'], ':message' => $_POST['message']);
- try{
- $stmt = $pdo->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex){
- // Fail early when a error occurs
- echo '<span style="color: red">ERROR! Code: 011</span>';
- exit;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement