diff options
Diffstat (limited to 'create_thread.php')
-rw-r--r-- | create_thread.php | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/create_thread.php b/create_thread.php index bc77cc7..dc0ce06 100644 --- a/create_thread.php +++ b/create_thread.php @@ -40,32 +40,7 @@ if (!isset($_SESSION['signed_in'])) { </form> <?php include_once 'includes/db_inc.php'; - -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) { - $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); -} +include_once 'includes/functions_insert.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $post_content = filter_input(INPUT_POST, 'post_content', FILTER_SANITIZE_STRING); @@ -78,9 +53,9 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { } else { insert_thread($dbc, $thread_subject, $thread_cat, $user_id); $thread_id = mysqli_insert_id($dbc); - insert_post($dbc, $post_content, $thread_id, $user_id); + insert_post($dbc, $post_content, $thread_id, $user_id, $thread_cat); - $sql = "UPDATE categories SET `cat_thread_count` = `cat_thread_count` + '1', `cat_post_count` = `cat_post_count` + '1' WHERE cat_id = " . $thread_cat . ";"; + $sql = "UPDATE categories SET `cat_thread_count` = `cat_thread_count` + '1' WHERE cat_id = " . $thread_cat . ";"; mysqli_query($dbc, $sql); header("Location: /forum/thread/" . $thread_id); |