diff options
-rw-r--r-- | category.php | 10 | ||||
-rw-r--r-- | create_thread.php (renamed from create_topic.php) | 40 | ||||
-rw-r--r-- | header.php | 2 | ||||
-rw-r--r-- | includes/db_inc.php | 2 | ||||
-rw-r--r-- | includes/register_inc.php | 0 | ||||
-rw-r--r-- | includes/reply_inc.php | 6 | ||||
-rw-r--r-- | index.php | 4 | ||||
-rw-r--r-- | setup.sql | 22 | ||||
-rw-r--r-- | thread.php (renamed from topic.php) | 18 |
9 files changed, 52 insertions, 52 deletions
diff --git a/category.php b/category.php index b444ef3..fcc7851 100644 --- a/category.php +++ b/category.php @@ -27,21 +27,21 @@ mysqli_free_result($result); echo '</section>'; -$sql = "SELECT topic_id, topic_subject, topic_date, user_name FROM topics LEFT JOIN users ON topic_author = user_id WHERE topic_cat = " . mysqli_real_escape_string($dbc, $_GET['id']) . " ORDER BY topic_id DESC"; +$sql = "SELECT thread_id, thread_subject, thread_date, user_name FROM threads LEFT JOIN users ON thread_author = user_id WHERE thread_cat = " . mysqli_real_escape_string($dbc, $_GET['id']) . " ORDER BY thread_id DESC"; $result = mysqli_query($dbc, $sql); if (!$result) { - die('Error trying to display topics: ' . mysqli_error($dbc)); + die('Error trying to display threads: ' . mysqli_error($dbc)); } // Display table of posts -echo '<table><tr><th class="left">Topic</th><th class="right">Latest Post</th></tr>'; +echo '<table><tr><th class="left">Thread</th><th class="right">Latest Post</th></tr>'; while ($row = mysqli_fetch_assoc($result)) { echo '<tr><td class="left">'; - echo '<h4><a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a></h4>'; - echo '<small>by <b>' . $row['user_name'] . '</b> on ' . date('M d, Y', strtotime($row['topic_date'])) . '</small></td><td class="right">by <b>cflip</b><br><small>01-22-2021 9:34</small></td></tr>'; + echo '<h4><a href="thread.php?id=' . $row['thread_id'] . '">' . $row['thread_subject'] . '</a></h4>'; + echo '<small>by <b>' . $row['user_name'] . '</b> on ' . date('M d, Y', strtotime($row['thread_date'])) . '</small></td><td class="right">by <b>cflip</b><br><small>01-22-2021 9:34</small></td></tr>'; } echo '</table>'; diff --git a/create_topic.php b/create_thread.php index 278d0fa..3f15f63 100644 --- a/create_topic.php +++ b/create_thread.php @@ -2,17 +2,17 @@ include_once 'header.php'; -echo '<section><h2>Create a new topic</h2>'; +echo '<section><h2>Create a new thread</h2>'; if (!isset($_SESSION['signed_in'])) { - die('You must be <a href="signin.php">signed in</a> to create a topic.'); + die('You must be <a href="signin.php">signed in</a> to create a thread.'); } ?> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post"> - <label for="topic_subject">Subject: </label><br> - <input type="text" name="topic_subject"><br> - <label for="topic_cat">Category: </label><br> + <label for="thread_subject">Subject: </label><br> + <input type="text" name="thread_subject"><br> + <label for="thread_cat">Category: </label><br> <?php include_once 'includes/db_inc.php'; @@ -27,7 +27,7 @@ if (!isset($_SESSION['signed_in'])) { die('There are currently no categories to post to.'); } - echo '<select name="topic_cat">'; + echo '<select name="thread_cat">'; while ($row = mysqli_fetch_assoc($result)) { echo '<option value="' . $row['cat_id'] . '">' . $row['cat_name'] . '</option>'; @@ -44,28 +44,28 @@ if (!isset($_SESSION['signed_in'])) { <?php 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(), ?, ?);"; +function create_thread($dbc, $thread_subject, $thread_cat, $thread_author) { + $sql = "INSERT INTO threads(thread_subject, thread_date, thread_cat, thread_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)); + die('Could not create thread due to internal error: ' . mysqli_error($dbc)); } - mysqli_stmt_bind_param($stmt, "sii", $topic_subject, $topic_cat, $topic_author); + mysqli_stmt_bind_param($stmt, "sii", $thread_subject, $thread_cat, $thread_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(), ?, ?);"; +function create_post($dbc, $post_content, $post_thread, $post_author) { + $sql = "INSERT INTO posts(post_content, post_date, post_thread, 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)); + die('Could not create thread due to internal error: ' . mysqli_error($dbc)); } - mysqli_stmt_bind_param($stmt, "sii", $post_content, $post_topic, $post_author); + mysqli_stmt_bind_param($stmt, "sii", $post_content, $post_thread, $post_author); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); } @@ -79,19 +79,19 @@ function validate($data) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $post_content = validate($_POST['post_content']); - $topic_subject = validate($_POST['topic_subject']); - $topic_cat = validate($_POST['topic_cat']); + $thread_subject = validate($_POST['thread_subject']); + $thread_cat = validate($_POST['thread_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); + create_thread($dbc, $thread_subject, $thread_cat, $user_id); + $thread_id = mysqli_insert_id($dbc); + create_post($dbc, $post_content, $thread_id, $user_id); if (!$post_result) { echo 'An error occurred creating your post: ' . mysqli_error($dbc); } - header("Location: topic.php?id=" . $topic_id); + header("Location: thread.php?id=" . $thread_id); } ?> @@ -14,7 +14,7 @@ session_start(); <h1 id="title">cflip.net forum<sub style="font-size: small;">beta</sub></h1> <nav> <a href="index.php">Home</a> - <a href="create_topic.php">Create a topic</a> + <a href="create_thread.php">Create a thread</a> <div id="user"> <?php diff --git a/includes/db_inc.php b/includes/db_inc.php index b76f06d..2d157af 100644 --- a/includes/db_inc.php +++ b/includes/db_inc.php @@ -3,7 +3,7 @@ $db_server = 'localhost'; $db_user = 'root'; $db_pass = ''; -$db_database = 'forum'; +$db_database = 'forum2'; $dbc = mysqli_connect($db_server, $db_user, $db_pass, $db_database); diff --git a/includes/register_inc.php b/includes/register_inc.php deleted file mode 100644 index e69de29..0000000 --- a/includes/register_inc.php +++ /dev/null diff --git a/includes/reply_inc.php b/includes/reply_inc.php index 480c651..d20c4ed 100644 --- a/includes/reply_inc.php +++ b/includes/reply_inc.php @@ -10,10 +10,10 @@ if ($_SERVER['REQUEST_METHOD'] != 'POST') { } if (!isset($_SESSION['signed_in'])) { - die('You must be signed in to reply to a topic.'); + die('You must be signed in to reply to a thread.'); } -$sql = "INSERT INTO posts(post_content, post_date, post_topic, post_author) VALUES(?, NOW(), ?, ?)"; +$sql = "INSERT INTO posts(post_content, post_date, post_thread, post_author) VALUES(?, NOW(), ?, ?)"; $stmt = mysqli_stmt_init($dbc); if (!mysqli_stmt_prepare($stmt, $sql)) { @@ -24,4 +24,4 @@ mysqli_stmt_bind_param($stmt, "sii", $_POST['reply_content'], $_GET['reply_to'], mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); -header("Location: ../topic.php?id=" . $_GET['reply_to']);
\ No newline at end of file +header("Location: ../thread.php?id=" . $_GET['reply_to']);
\ No newline at end of file @@ -4,7 +4,7 @@ include_once 'header.php'; <table> <tr> <th class="left">Category</th> - <th class="right">Latest Topic</th> + <th class="right">Latest Thread</th> </tr> <?php include_once 'includes/db_inc.php'; @@ -20,7 +20,7 @@ include_once 'header.php'; echo '<tr><td class="left">'; echo '<h4><a href="category.php?id=' . $row['cat_id'] . '">' . $row['cat_name'] . '</a></h4>'; echo $row['cat_description']; - echo '</td><td class="right">Example topic right here<br><small>1 hour ago by <b>cflip</b></small></td></tr>'; + echo '</td><td class="right">Example thread<br><small>1 hour ago by <b>example user</b></small></td></tr>'; } mysqli_free_result($result); @@ -15,25 +15,25 @@ CREATE TABLE categories ( PRIMARY KEY (cat_id) ) ENGINE = InnoDB; -CREATE TABLE topics ( - topic_id INT(8) NOT NULL AUTO_INCREMENT, - topic_subject VARCHAR(255) NOT NULL, - topic_date DATETIME NOT NULL, - topic_cat INT(8) NOT NULL, - topic_author INT(8) NOT NULL, - PRIMARY KEY (topic_id) +CREATE TABLE threads ( + thread_id INT(8) NOT NULL AUTO_INCREMENT, + thread_subject VARCHAR(255) NOT NULL, + thread_date DATETIME NOT NULL, + thread_cat INT(8) NOT NULL, + thread_author INT(8) NOT NULL, + PRIMARY KEY (thread_id) ) ENGINE = InnoDB; CREATE TABLE posts ( post_id INT(8) NOT NULL AUTO_INCREMENT, post_content TEXT NOT NULL, post_date DATETIME NOT NULL, - post_topic INT(8) NOT NULL, + post_thread INT(8) NOT NULL, post_author INT(8) NOT NULL, PRIMARY KEY (post_id) ) ENGINE = InnoDB; -ALTER TABLE topics ADD FOREIGN KEY(topic_cat) REFERENCES categories(cat_id) ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE topics ADD FOREIGN KEY(topic_author) REFERENCES users(user_id) ON DELETE RESTRICT ON UPDATE CASCADE; -ALTER TABLE posts ADD FOREIGN KEY(post_topic) REFERENCES topics(topic_id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE threads ADD FOREIGN KEY(thread_cat) REFERENCES categories(cat_id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE threads ADD FOREIGN KEY(thread_author) REFERENCES users(user_id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE posts ADD FOREIGN KEY(post_thread) REFERENCES threads(thread_id) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE posts ADD FOREIGN KEY(post_author) REFERENCES users(user_id) ON DELETE RESTRICT ON UPDATE CASCADE; @@ -3,20 +3,20 @@ <?php include_once 'includes/db_inc.php'; -$sql = "SELECT topic_id, topic_subject, topic_date, user_id, user_name FROM topics LEFT JOIN users ON topic_author = user_id WHERE topic_id = " . mysqli_real_escape_string($dbc, $_GET['id']); +$sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name FROM threads LEFT JOIN users ON thread_author = user_id WHERE thread_id = " . mysqli_real_escape_string($dbc, $_GET['id']); $result = mysqli_query($dbc, $sql); if (!$result) { - die('Error trying to display topic page: ' . mysqli_error()); + die('Error trying to display thread page: ' . mysqli_error($dbc)); } if (mysqli_num_rows($result) == 0) { - echo 'This topic does not exist'; + echo 'This thread does not exist'; } else { while ($row = mysqli_fetch_assoc($result)) { - echo '<section><h1>' . $row['topic_subject'] . '</h1>'; - echo 'Created by <b>' . $row['user_name'] . '</b> on ' . date('M d, Y', strtotime($row['topic_date'])) . '</section>'; - $topic_id = $row['topic_id']; + echo '<section><h1>' . $row['thread_subject'] . '</h1>'; + echo 'Created by <b>' . $row['user_name'] . '</b> on ' . date('M d, Y', strtotime($row['thread_date'])) . '</section>'; + $thread_id = $row['thread_id']; } } @@ -24,7 +24,7 @@ echo '</section>'; mysqli_free_result($result); -$sql = "SELECT post_content, post_date, post_author, user_id, user_name FROM posts LEFT JOIN users ON post_author = user_id WHERE post_topic = " . mysqli_real_escape_string($dbc, $_GET['id']); +$sql = "SELECT post_content, post_date, post_author, user_id, user_name FROM posts LEFT JOIN users ON post_author = user_id WHERE post_thread = " . mysqli_real_escape_string($dbc, $_GET['id']); $result = mysqli_query($dbc, $sql); if (!$result) { @@ -32,7 +32,7 @@ if (!$result) { } if (mysqli_num_rows($result) == 0) { - echo '<section>This topic has no posts</section>'; + echo '<section>This thread has no posts</section>'; } else { echo '<table>'; while ($row = mysqli_fetch_assoc($result)) { @@ -47,7 +47,7 @@ mysqli_free_result($result); if (isset($_SESSION['signed_in'])) { echo ' <section> - <form action="includes/reply_inc.php?reply_to=' . $topic_id .'>" method="post"> + <form action="includes/reply_inc.php?reply_to=' . $thread_id .'" method="post"> <h2>Reply to this thread</h2> <textarea name="reply_content"></textarea> <br> |