-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquestion.php
executable file
·95 lines (92 loc) · 2.91 KB
/
question.php
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/connection.php") ?>
<?php require_once("includes/functions.php") ?>
<?php require_once("includes/form_functions.php") ?>
<?php require_once("includes/header.php") ?>
<?php
if(is_null(check_login())){
redirect_to("index.php");
}
$sel_event = get_event_by_id($_SESSION['event']);
if(!isset($sel_event)) {
redirect_to("index.php");
}
?>
<?php
if (isset($_POST['submit'])) {
if (isset($_POST['content']) && !empty($_POST['content'])) {
$content = mysql_comment_prep($_POST["content"]);
$query = "INSERT INTO comments (
user_id, question_id, content, date_id
) values (
{$_SESSION['user_id']}, {$_SESSION['question']}, '{$content}', now()
)";
if(mysql_query($query, $connection)) {
redirect_to("question.php?qes={$_SESSION['question']}");
} else {
//echo mysql_error();
echo "<p>Could not post!!</p>";
}
}
}
?>
<div class="content clearfix">
<div class="chapter grid_8 alpha">
<?php
if(!intval($_GET['qes'])) {
redirect_to("event.php");
}
if(isset($_GET['qes'])) {
$question_id = $_GET['qes'];
$_SESSION['question'] = $question_id;
} elseif(isset($_SESSION['question'])) {
$question_id = $_SESSION['question'];
} else {
redirect_to("event.php");
}
if(!is_null(get_question_by_id($question_id))) {
$question = get_question_by_id($question_id);
echo "<h2>";
echo htmlspecialchars_decode($question['name']);
echo "</h2>";
echo htmlspecialchars_decode($question['content']);
} else {
redirect_to("event.php");
}
?>
</div>
<div class="event grid_4 omega">
<?php get_upcoming_event(); ?>
</div>
<div class="chapter grid_8 alpha">
<?php
$comments_set = get_comments_by_question_id($question_id);
if(mysql_num_rows($comments_set) == 0) {
echo "<p>No one commented.</p>";
}
while($comment = mysql_fetch_array($comments_set)) {
$output = "<div class=\"comment\">";
$user = get_user_by_id($comment['user_id']);
$output .= "<h2>{$user['username']}<span> @ {$comment['date_id']}<span></h2>";
$output .= "<p>{$comment['content']}</p>";
$output .= "</div>";
echo $output;
}
?>
</div>
<div class="event grid_4 omega">
<p>Please don't get carried away or I will have to personally meet you.</p>
</div>
<div class="chapter grid_8 alpha">
<form action="question.php?qes=<?php echo urlencode($_GET['qes']); ?>" method="POST" class="bootstrap-frm">
<h1>Comment Below</h1>
<label>
<textarea id="content" name="content" placeholder="Write your comment. Please don't insert code."></textarea>
</label>
<label>
<input type="submit" name="submit" class="button" value="Submit" />
</label>
</form>
</div>
</div>
<?php include("includes/footer.php") ?>