summaryrefslogtreecommitdiff
path: root/includes/reply_inc.php
diff options
context:
space:
mode:
authorCflip <36554078+cflip@users.noreply.github.com>2021-01-22 20:45:43 -0700
committerCflip <36554078+cflip@users.noreply.github.com>2021-01-22 20:45:43 -0700
commitdf49a36e140acc211fdc31480d40281404110310 (patch)
tree3a25af561ed3703ad5df8cf90d9f56d8824f7a4f /includes/reply_inc.php
Inital commit with existing code
Diffstat (limited to 'includes/reply_inc.php')
-rw-r--r--includes/reply_inc.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/includes/reply_inc.php b/includes/reply_inc.php
new file mode 100644
index 0000000..7f53fce
--- /dev/null
+++ b/includes/reply_inc.php
@@ -0,0 +1,33 @@
+<?php
+
+session_start();
+
+include_once 'db_inc.php';
+
+if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ die('This file cannot be called directly.');
+}
+
+if (!isset($_SESSION['signed_in'])) {
+ die('You must be signed in to reply to a topic.');
+}
+
+$sql = "INSERT INTO posts(post_content, post_date, post_topic, post_author) VALUES(?, NOW(), ?, ?)";
+$stmt = mysqli_stmt_init($dbc);
+
+if (!mysqli_stmt_prepare($stmt, $sql)) {
+ die('Failed to process statement: ' . mysqli_error($dbc));
+}
+
+mysqli_stmt_bind_param($stmt, "sii", $_POST['post_content'], $_GET['reply_to'], $_SESSION['user_id']);
+mysqli_stmt_execute($stmt);
+
+$result = mysqli_stmt_get_result($stmt);
+
+if (!$result) {
+ echo 'An error occurred trying to reply to the post. ' . mysqli_error($dbc);
+} else {
+ echo 'Your reply has been saved, check out <a href="topic.php?id=' . $_GET['reply_to'] . '">the topic</a>.';
+}
+
+//header("Location: ../topic.php?id=" . $_GET['reply_to']); \ No newline at end of file