summaryrefslogtreecommitdiff
path: root/create_topic.php
blob: 2953646b67e315f49d30b0bc524d9377c5fd951e (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
<?php

include_once 'header.php';

echo '<section><h2>Create a new topic</h2>';

if (!isset($_SESSION['signed_in'])) {
	die('You must be <a href="signin.php">signed in</a> to create a topic.');
} 
?>

<form action="includes/topic_inc.php" method="post">
	<label for="topic_subject">Subject: </label><br>
	<input type="text" name="topic_subject"><br>
	<label for="topic_cat">Category: </label><br>
	<select name="topic_cat">';
		<?php
		include_once 'includes/db_inc.php';

		$sql = "SELECT cat_id, cat_name, cat_description FROM categories";
		$result = mysqli_query($dbc, $sql);

		if (!$result) {
			die('Error trying to fetch category list: ' . mysqli_error($dbc));
		} 

		if (mysqli_num_rows($result) == 0) {
			die('There are currently no categories to post to.');
		} 

		while ($row = mysqli_fetch_assoc($result)) {
			echo '<option value="' . $row['cat_id'] . '">' . $row['cat_name'] . '</option>';
		}
		?>
	</select><br>
	<label for="post_content">Write your post: </label><br>
	<textarea name="post_content"></textarea><br>
	<input type="submit" name="submit">
</form>
</section>

<?php
include 'footer.php';
?>