summaryrefslogtreecommitdiff
path: root/includes/functions_insert.php
blob: e13b80e0a9c0d5afc7a2de5fc7a67817b614f9a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
}