forked from if-itb/IF3110-2015-T1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vote.php
47 lines (39 loc) · 938 Bytes
/
vote.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
<?php
include 'dbfunctions.php';
$conn=ConnectToDatabase();
$id = $_GET['id'];
$qa = $_GET['qa'];
$updown = $_GET['updown'];
if($qa=="question") {
$result = GetQuestion($id);
$vote = $result["question_vote"];
if($updown=="up") {
$vote++;
}
else {
$vote--;
}
$sql = "UPDATE Question SET question_vote=$vote WHERE Question.question_id=$id";
if (!mysqli_query($conn, $sql)) {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
$result = GetQuestion($id);
echo $result["question_vote"];
}
else { //qa="answer"
$result = GetAnswer($id);
$vote = $result["answer_vote"];
if($updown=="up") {
$vote++;
}
else {
$vote--;
}
$sql = "UPDATE Answer SET answer_vote=$vote WHERE Answer.answer_id=$id";
if (!mysqli_query($conn, $sql)) {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
$result = GetAnswer($id);
echo $result["answer_vote"];
}
?>