summaryrefslogtreecommitdiff
path: root/includes/topic_inc.php
diff options
context:
space:
mode:
authorCflip <36554078+cflip@users.noreply.github.com>2021-01-22 21:40:51 -0700
committerCflip <36554078+cflip@users.noreply.github.com>2021-01-22 21:40:51 -0700
commitb49c2533c5a82332113d125a40712ab50adade81 (patch)
treef2cd05c698684491f93e492db9124263e148b9da /includes/topic_inc.php
parentdf49a36e140acc211fdc31480d40281404110310 (diff)
Fix broken pages
Diffstat (limited to 'includes/topic_inc.php')
-rw-r--r--includes/topic_inc.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/includes/topic_inc.php b/includes/topic_inc.php
new file mode 100644
index 0000000..c16a4e0
--- /dev/null
+++ b/includes/topic_inc.php
@@ -0,0 +1,47 @@
+<?php
+
+include_once 'db_inc.php';
+
+session_start();
+
+$sql = "BEGIN WORK;";
+$result = mysqli_query($dbc, $sql);
+
+if (!$result) {
+ echo 'An error occurred creating your topic. Try again later';
+}
+
+$sql = "INSERT INTO topics(topic_subject, topic_date, topic_cat, topic_author) VALUES(
+'" . mysqli_real_escape_string($dbc, $_POST['topic_subject']) . "',
+NOW(),
+" . mysqli_real_escape_string($dbc, $_POST['topic_cat']) . ",
+" . $_SESSION['user_id'] .")";
+
+$result = mysqli_query($dbc, $sql);
+
+if (!$result) {
+ echo 'An error occured while creating your post. Please try again later.' . mysql_error();
+ $sql = "ROLLBACK;";
+ mysqli_query($dbc, $sql);
+} else {
+ $topic_id = mysqli_insert_id($dbc);
+
+ $sql = "INSERT INTO posts(post_content, post_date, post_topic, post_author) VALUES(
+ '" . mysqli_real_escape_string($dbc, $_POST['post_content']) . "',
+ NOW(),
+ " . $topic_id . ",
+ " . $_SESSION['user_id'] . ")";
+
+ $result = mysqli_query($dbc, $sql);
+
+ if (!$result) {
+ echo 'An error occured while creating your post. Please try again later.' . mysqli_error($dbc);
+ $sql = "ROLLBACK;";
+ mysqli_query($dbc, $sql);
+ } else {
+ $sql = "COMMIT;";
+ $result = mysqli_query($dbc, $sql);
+ }
+}
+
+header("Location: ../topic.php?id=" . $topic_id); \ No newline at end of file