summaryrefslogtreecommitdiff
path: root/thread.php
blob: 52ad8b37370b4ac36fca33b95ba47b1aae67e946 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php include_once 'header.php'; ?>

<?php
include_once 'includes/db_inc.php';

$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 thread page: ' . mysqli_error($dbc));
} 

if (mysqli_num_rows($result) == 0) {
	echo 'This thread does not exist';
} else {
	while ($row = mysqli_fetch_assoc($result)) {
		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'];
	}
}

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_thread = " . mysqli_real_escape_string($dbc, $_GET['id']);
$result = mysqli_query($dbc, $sql);

if (!$result) {
	die('Error trying to display posts: ' . mysqli_error($dbc));
}

if (mysqli_num_rows($result) == 0) {
	echo '<section>This thread has no posts</section>';
} else {
	echo '<table>';
	while ($row = mysqli_fetch_assoc($result)) {
		echo '<tr class="post"><td class="right">Posted by <b>' . $row['user_name'] . '</b><br><small>' . date('m/d/Y g:ia', strtotime($row['post_date'])) . '</small></td>';
		echo '<td class="left">' . $row['post_content'] . '</td></tr>';
	}
	echo '</table>';
}

mysqli_free_result($result);

if (isset($_SESSION['signed_in'])) {
	echo '
	<section>
		<form action="includes/reply_inc.php?reply_to=' . $thread_id .'" method="post">
			<h2>Reply to this thread</h2>
			<textarea name="reply_content"></textarea>
			<br>
			<input type="submit" name="submit">
		</form>
	</section>
	';
} else {
	echo '
	<section>
		<a href="signin.php">Sign in</a> to reply to this thread</a>
	</section>
	';
}

include_once 'footer.php';
?>