Login/Register/confirm and new comment feature
This commit is contained in:
@@ -1,31 +1,25 @@
|
||||
<?php
|
||||
include_once "../../../base/settings.php";
|
||||
include_once "../../../base/headers.php";
|
||||
include_once "../../../base/database.php";
|
||||
include_once "../queries.php";
|
||||
|
||||
session_name("PHP_SESSION_guestBook");
|
||||
session_start();
|
||||
$user = $_SESSION["user"] ?? null;
|
||||
$_SESSION["error"] = [];
|
||||
|
||||
if (!isset($_POST["title"])) {
|
||||
array_push($_SESSION["error"], "Title was not among the data sent.");
|
||||
}
|
||||
if (!isset($_POST["name"])) {
|
||||
array_push($_SESSION["error"], "Name was not among the data sent.");
|
||||
if (!isset($user)) {
|
||||
Headers::redirect("../login");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($_POST["comment"])) {
|
||||
array_push($_SESSION["error"], "Comment was not among the data sent.");
|
||||
}
|
||||
|
||||
$title = trim($_POST["title"]);
|
||||
$name = trim($_POST["name"]);
|
||||
$comment = substr(trim($_POST["comment"]), 0, 250);
|
||||
$time = time();
|
||||
|
||||
if ($title === "") {
|
||||
array_push($_SESSION["error"], "The title was empty.");
|
||||
}
|
||||
if ($name === "") {
|
||||
array_push($_SESSION["error"], "The name was empty.");
|
||||
}
|
||||
if ($comment === "") {
|
||||
array_push($_SESSION["error"], "The comment was empty.");
|
||||
}
|
||||
@@ -35,11 +29,13 @@ if (count($_SESSION["error"]) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$string = file_get_contents("../data/data.json") ?? "[]";
|
||||
$json = json_decode($string);
|
||||
$db = DB::openConnection();
|
||||
|
||||
array_push($json, ["time" => $time, "title" => $title, "name" => $name, "comment" => $comment]);
|
||||
$stmt = $db->prepare($insertCommentQuery);
|
||||
$stmt->bindValue(":UID", $user["id"]);
|
||||
$stmt->bindValue(":COM", $comment);
|
||||
$stmt->execute();
|
||||
|
||||
file_put_contents("../data/data.json", json_encode($json));
|
||||
DB::closeConnection($db);
|
||||
|
||||
Headers::redirect("../");
|
||||
|
||||
Reference in New Issue
Block a user