55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
function sendmessage($message_content, $message_by, $message_to) {
|
|
global $db;
|
|
$req = $db->prepare('INSERT INTO `messages` (message_content, message_by, message_to, message_datetime) VALUES (:message_content, :message_by, :message_to, NOW())');
|
|
$req->execute(array(
|
|
"message_content"=>$message_content,
|
|
"message_by"=>$message_by,
|
|
"message_to"=>$message_to
|
|
));
|
|
}
|
|
|
|
|
|
session_reset();
|
|
session_start();
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
|
|
require "$root/database/credentials.php";
|
|
// Connect the database
|
|
try {
|
|
$db = new PDO("mysql:host=$host;dbname=$database;charset=utf8",
|
|
$user,
|
|
$password,
|
|
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
|
));
|
|
} catch (Exception $e) {
|
|
die("Error : ".$e->getMessage());
|
|
}
|
|
$_SESSION['error_msg'] = "";
|
|
if (isset($_POST['submit'])) {
|
|
if (isset($_POST['message_by'])) {
|
|
$message_by = $_POST['message_by'];
|
|
} else {
|
|
$_SESSION['error_msg'] .= _('Error: No message author').'\n';
|
|
}
|
|
if (isset($_POST['message_to'])) {
|
|
$message_to = $_POST['message_to'];
|
|
} else {
|
|
$_SESSION['error_msg'] .= _('Error: No message destinator').'\n';
|
|
} if (isset($_POST['message_content'])) {
|
|
$message_content = $_POST['message_content'];
|
|
} else {
|
|
$_SESSION['error_msg'] .= _('Error: No message content').'\n';
|
|
}
|
|
|
|
if (isset($_SESSION['error_msg']) and $_SESSION['error_msg'] != "") {
|
|
header('Location: /discussion');
|
|
} else {
|
|
sendmessage($message_content, $message_by, $message_to);
|
|
header('Location: /discussion/messages/?author='.$message_to);
|
|
}
|
|
}
|