-
Notifications
You must be signed in to change notification settings - Fork 0
/
send-message.php
47 lines (38 loc) · 975 Bytes
/
send-message.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require_once "./logindb.php";
$db = pg_connect($connection_string) or die('Impossibile connettersi al database!');
session_start();
// Controllo di sicurezza.
if (!isset($_SESSION['email'])) {
echo "Sessione non valida!";
pg_close($db);
exit();
}
$email = $_SESSION['email'];
// Controllo ridondante (sicurezza).
if (!isset($_POST['message'])) {
echo "Richiesta non valida!";
pg_close($db);
exit();
}
$message = trim($_POST['message']);
// Controllo ridondante (sicurezza).
if (trim($message) == '') {
pg_close($db);
exit();
}
// Aggiunge il messaggio alla tabella "post".
$sql = 'INSERT INTO "post" ("email", "text") VALUES ($1, $2)';
$result = pg_prepare($db, "Send-Message", $sql);
if (!$result) {
echo pg_last_error($db);
pg_close($db);
exit();
}
$result = pg_execute($db, "Send-Message", array($email, $message));
if (!$result) {
echo pg_last_error($db);
pg_close($db);
exit();
}
pg_close($db);