summaryrefslogtreecommitdiff
path: root/includes/reply_inc.php
blob: 7f53fceddceb036418e3b612364ad07fc417383e (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
<?php

session_start();

include_once 'db_inc.php';

if ($_SERVER['REQUEST_METHOD'] != 'POST') {
	die('This file cannot be called directly.');
} 

if (!isset($_SESSION['signed_in'])) {
	die('You must be signed in to reply to a topic.');
} 

$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('Failed to process statement: ' . mysqli_error($dbc));
}

mysqli_stmt_bind_param($stmt, "sii", $_POST['post_content'], $_GET['reply_to'], $_SESSION['user_id']);
mysqli_stmt_execute($stmt);

$result = mysqli_stmt_get_result($stmt);

if (!$result) {
	echo 'An error occurred trying to reply to the post. ' . mysqli_error($dbc);
} else {
	echo 'Your reply has been saved, check out <a href="topic.php?id=' . $_GET['reply_to'] . '">the topic</a>.';
}

//header("Location: ../topic.php?id=" . $_GET['reply_to']);