From 19a3704acbf9801c0b1491a84828496ef46bc840 Mon Sep 17 00:00:00 2001 From: Cflip <36554078+cflip@users.noreply.github.com> Date: Sat, 23 Jan 2021 11:24:05 -0700 Subject: Form cleanup and better password hashing --- create_topic.php | 69 +++++++++++++++++++++++++++++++++++----- header.php | 4 +-- includes/signout_inc.php | 1 + includes/topic_inc.php | 47 --------------------------- register.php | 82 +++++++++++++++++++++++++++--------------------- reply.php | 30 ------------------ signin.php | 68 ++++++++++++++++++++++++--------------- topic.php | 36 +++++++++++++-------- 8 files changed, 176 insertions(+), 161 deletions(-) delete mode 100644 includes/topic_inc.php delete mode 100644 reply.php diff --git a/create_topic.php b/create_topic.php index 2953646..278d0fa 100644 --- a/create_topic.php +++ b/create_topic.php @@ -9,12 +9,11 @@ if (!isset($_SESSION['signed_in'])) { } ?> -
+" method="post">


-
+ + echo '
'; + ?>

@@ -40,5 +42,58 @@ if (!isset($_SESSION['signed_in'])) { \ No newline at end of file +include_once 'includes/db_inc.php'; + +function create_topic($dbc, $topic_subject, $topic_cat, $topic_author) { + $sql = "INSERT INTO topics(topic_subject, topic_date, topic_cat, topic_author) VALUES(?, NOW(), ?, ?);"; + $stmt = mysqli_stmt_init($dbc); + + if (!mysqli_stmt_prepare($stmt, $sql)) { + die('Could not create topic due to internal error: ' . mysqli_error($dbc)); + } + + mysqli_stmt_bind_param($stmt, "sii", $topic_subject, $topic_cat, $topic_author); + mysqli_stmt_execute($stmt); + mysqli_stmt_close($stmt); +} + +function create_post($dbc, $post_content, $post_topic, $post_author) { + $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('Could not create topic due to internal error: ' . mysqli_error($dbc)); + } + + mysqli_stmt_bind_param($stmt, "sii", $post_content, $post_topic, $post_author); + mysqli_stmt_execute($stmt); + mysqli_stmt_close($stmt); +} + +function validate($data) { + $data = trim($data); + $data = stripslashes($data); + $data = htmlspecialchars($data); + return $data; +} + +if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $post_content = validate($_POST['post_content']); + $topic_subject = validate($_POST['topic_subject']); + $topic_cat = validate($_POST['topic_cat']); + $user_id = validate($_SESSION['user_id']); + + create_topic($dbc, $topic_subject, $topic_cat, $user_id); + $topic_id = mysqli_insert_id($dbc); + create_post($dbc, $post_content, $topic_id, $user_id); + + if (!$post_result) { + echo 'An error occurred creating your post: ' . mysqli_error($dbc); + } + + header("Location: topic.php?id=" . $topic_id); +} + +?> + + \ No newline at end of file diff --git a/header.php b/header.php index 935f063..9d57fba 100644 --- a/header.php +++ b/header.php @@ -5,13 +5,13 @@ session_start(); - cflip.net forum Beta + cflip.net forum
-

cflip.net forum

+

cflip.net forumbeta