diff options
author | cflip <36554078+cflip@users.noreply.github.com> | 2021-03-24 19:01:51 -0600 |
---|---|---|
committer | cflip <36554078+cflip@users.noreply.github.com> | 2021-03-24 19:01:51 -0600 |
commit | 0ecae4e72d7d4ace51b731ff2c5d5eb63351e3e1 (patch) | |
tree | 40ddad473bfc2e3e5c215da9ee0853044695737c /includes/functions_insert.php | |
parent | c9732788143886b611cb2fecfb53daf3d8add48f (diff) |
Add thread replies, sort threads by last reply
Diffstat (limited to 'includes/functions_insert.php')
-rw-r--r-- | includes/functions_insert.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/includes/functions_insert.php b/includes/functions_insert.php new file mode 100644 index 0000000..e13b80e --- /dev/null +++ b/includes/functions_insert.php @@ -0,0 +1,35 @@ +<?php + +// This file may be replaced by a MVC controller later on + +function insert_thread($dbc, $thread_subject, $thread_cat, $thread_author) { + $sql = "INSERT INTO threads(thread_subject, thread_date_created, thread_date_lastpost, thread_category, thread_author) VALUES (?, CONVERT_TZ(NOW(), 'SYSTEM', '+00:00'), CONVERT_TZ(NOW(), 'SYSTEM', '+00:00'), ?, ?);"; + $stmt = mysqli_stmt_init($dbc); + + if (!mysqli_stmt_prepare($stmt, $sql)) { + die('Could not create thread due to internal error: ' . mysqli_error($dbc)); + } + + mysqli_stmt_bind_param($stmt, "sii", $thread_subject, $thread_cat, $thread_author); + mysqli_stmt_execute($stmt); + mysqli_stmt_close($stmt); +} + +function insert_post($dbc, $post_content, $post_thread, $post_author, $post_category) { + $sql = "INSERT INTO posts(post_content, post_date, post_thread, post_author) VALUES (?, CONVERT_TZ(NOW(), 'SYSTEM', '+00:00'), ?, ?);"; + $stmt = mysqli_stmt_init($dbc); + + if (!mysqli_stmt_prepare($stmt, $sql)) { + die('Could not create post due to internal error: ' . mysqli_error($dbc)); + } + + mysqli_stmt_bind_param($stmt, "sii", $post_content, $post_thread, $post_author); + mysqli_stmt_execute($stmt); + mysqli_stmt_close($stmt); + + $sql = "UPDATE categories SET `cat_post_count` = `cat_post_count` + '1' WHERE cat_id = " . $post_category . ";"; + mysqli_query($dbc, $sql); + + $sql = "UPDATE threads SET thread_date_lastpost = CONVERT_TZ(NOW(), 'SYSTEM', '+00:00') WHERE thread_id = " . $post_thread . ";"; + mysqli_query($dbc, $sql); +}
\ No newline at end of file |