-
Notifications
You must be signed in to change notification settings - Fork 0
/
addpost.php
64 lines (53 loc) · 1.89 KB
/
addpost.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
<?php
error_reporting(E_ALL & ~E_DEPRECATED);
session_start();
/* Classes importeren */
include_once('Classes/User.php');
include_once('Classes/Template.php');
/* Includes importeren */
include_once('Includes/connect.php');
include_once('Includes/slashes.php');
/* Classes initialiseren */
$cUser = new User();
/* Verbinden met mysql */
connectDB();
try {
if(!isset($_GET['id'])) {
throw new Exception('Game id parameter missing');
}
if(!isset($_GET['topicid'])) {
throw new Exception('Topic id parameter missing');
}
if($_SERVER['REQUEST_METHOD'] != 'POST' || !isset($_POST['reactie'])) {
throw new Exception('Form isn\'t posted');
}
$sql = 'SELECT EXISTS(
SELECT * FROM topics t
JOIN spellenhulp sh ON sh.topicid = t.topicid
WHERE t.topicid = '.add($_GET['topicid']).'
AND sh.spelid = '.add($_GET['id']).'
) as topic_exists';
$result = mysql_query($sql);
if(!$result) {
throw new Exception('Error finding the topic from the database');
}
$data = mysql_fetch_assoc($result);
if(!$data || !$data['topic_exists']) {
throw new Exception('Topic doesn\'t exist');
}
if (($cUser->checkSession()) || ($cUser->checkCookie())) {
$sQuery = "INSERT INTO berichten (topicid, userid, bericht, datum, tijd)
VALUES ('" . add($_GET['topicid']) . "', '" . $cUser->m_iUserid . "',
'" . add($_POST['reactie']) . "', NOW(), NOW());";
if (mysql_query($sQuery)) {
$cUser->addPost();
header('Location: gameview.php?id=' . $_GET['id'] . '&topicid=' . $_GET['topicid']);
} else {
throw new Exception('Error adding game comment');
}
} else {
header('Location: loginForm.php');
}
} catch (Exception $e) {
header('HTTP/1.0 404 Page not Found');
}