This repository was archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_add_review.php
More file actions
60 lines (48 loc) · 1.38 KB
/
post_add_review.php
File metadata and controls
60 lines (48 loc) · 1.38 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
require_once("php/tools.php");
require_once("php/database.php");
$user_id = isset($_SESSION["id"]) ? $_SESSION["id"] : "";
if ($user_id == "") {
header("location: login.php");
exit();
}
$film_id = isset($_POST["film_id"]) ? $_POST["film_id"] : "";
$voto = isset($_POST["voto"]) ? $_POST["voto"] : "";
$testo = isset($_POST["testo"]) ? $_POST["testo"] : "";
if ($film_id == "") {
Tools::errCode(500);
exit();
}
$err = [];
if (intval($voto) < 1 || intval($voto) > 10) {
array_push($err, "Devi esprimere un voto da 1 a 10.");
}
if (strlen($testo) < 5 || strlen($testo) > 1000) {
array_push($err, "La recensione deve contenere tra i 5 e i 1000 caratteri.");
}
if (! preg_match("/^[^<>{}]*$/", $testo)) {
array_push($err, "La recensione contiene caratteri non ammessi.");
}
if (preg_match("/^[\s]+$/", $testo)) {
array_push($err,"La recensione non può contenere solo spazi.");
}
if ($err) {
$_SESSION["error"] = $err;
header("location: film.php?id=" . $film_id);
exit();
}
try {
$connessione = new Database();
$res = $connessione->insertValutazione($user_id, $film_id, $voto, $testo);
unset($connessione);
} catch (Exception) {
unset($connessione);
Tools::errCode(500);
exit();
}
if (! $res)
$_SESSION["error"] = ["Errore durante l'inserimento della recensione."];
else
$_SESSION["success"] = ["Recensione inserita correttamente."];
header("location: film.php?id=" . $film_id);
?>