summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/db_inc.php12
-rw-r--r--includes/reply_inc.php33
-rw-r--r--includes/signout_inc.php5
3 files changed, 50 insertions, 0 deletions
diff --git a/includes/db_inc.php b/includes/db_inc.php
new file mode 100644
index 0000000..b76f06d
--- /dev/null
+++ b/includes/db_inc.php
@@ -0,0 +1,12 @@
+<?php
+
+$db_server = 'localhost';
+$db_user = 'root';
+$db_pass = '';
+$db_database = 'forum';
+
+$dbc = mysqli_connect($db_server, $db_user, $db_pass, $db_database);
+
+if (!$dbc) {
+ die("Database connection error: " . mysqli_connect_error());
+}
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
diff --git a/includes/signout_inc.php b/includes/signout_inc.php
new file mode 100644
index 0000000..c86447a
--- /dev/null
+++ b/includes/signout_inc.php
@@ -0,0 +1,5 @@
+<?php
+
+session_start();
+session_destroy();
+header("Location: ../index.php"); \ No newline at end of file