-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.php
85 lines (72 loc) · 3.06 KB
/
server.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
<?php
include 'logindetails.php';
echo $username, $password, $databasename,
// Connect using host, username, password and databasename
$link = mysqli_connect('xml.csc.kth.se', $username, $password, $databasename);
if (!$conn) {
die('Connection failed ' . mysqli_error($conn));
}
if (isset($_POST['save'])) {
$placeName = $_POST['placeName'];
$personName = $_POST['personName'];
$coffeeGrade = $_POST['coffeeGrade'];
$priceGrade = $_POST['priceGrade'];
$atmosphereGrade = $_POST['atmosphereGrade'];
$uniqueAvGrade = (intval($coffeeGrade) + intval($priceGrade) + intval($atmosphereGrade))/3;
$sql = "INSERT INTO Grade (placeName, personName, coffeeGrade, priceGrade, atmosphereGrade, uniqueAvGrade)
VALUES ('{$placeName}', '{$personName}', '{$coffeeGrade}', '{$priceGrade}', '{$atmosphereGrade}', '{$uniqueAvGrade}')";
if (mysqli_query($conn, $sql)) {
$id = mysqli_insert_id($conn);
$saved_comment = '<div class="comment_box">
<span class="delete" data-id="' . $id . '" >delete</span>
<span class="edit" data-id="' . $id . '">edit</span>
<div class="display_placeName">'. $placeName .'</div>
<div class="display_personName">'. $personName .'</div>
<div class="display_coffeeGrade">'. $coffeeGrade .'</div>
<div class="display_priceGrade">'. $priceGrade .'</div>
<div class="display_atmosphereGrade">'. $atmosphereGrade .'</div>
</div>';
//echo $saved_comment;
echo "Grade saved!";
}else {
echo "Error: you have already voted! Use the 'UPDATE' button.";
}
exit();
}
// delete comment fromd database
if (isset($_GET['delete'])) {
$id = $_GET['id'];
$sql = "DELETE FROM Grade WHERE id=" . $id;
mysqli_query($conn, $sql);
exit();
}
// update comment database:
if (isset($_POST['update'])) {
$id = $_POST['id'];
$placeName = $_POST['placeName'];
$personName = $_POST['personName'];
$coffeeGrade = $_POST['coffeeGrade'];
$priceGrade = $_POST['priceGrade'];
$atmosphereGrade = $_POST['atmosphereGrade'];
$uniqueAvGrade = (intval($coffeeGrade) + intval($priceGrade) + intval($atmosphereGrade))/3;
$sql2 = "UPDATE Grade SET coffeeGrade='{$coffeeGrade}', priceGrade='{$priceGrade}', atmosphereGrade='{$atmosphereGrade}',
uniqueAvGrade='{$uniqueAvGrade}' WHERE placeName='{$placeName}' AND personName='{$personName}'";
if (mysqli_query($conn, $sql2)) {
$id = mysqli_insert_id($conn);
$saved_comment = '<div class="comment_box">
<span class="delete" data-id="' . $id . '" >delete</span>
<span class="edit" data-id="' . $id . '">edit</span>
<div class="display_placeName">'. $placeName .'</div>
<div class="display_personName">'. $personName .'</div>
<div class="display_coffeeGrade">'. $coffeeGrade .'</div>
<div class="display_priceGrade">'. $priceGrade .'</div>
<div class="display_atmosphereGrade">'. $atmosphereGrade .'</div>
</div>';
//echo $saved_comment;
echo "Grade updated!";
}else {
echo "Error: No grade under that name found. Use the 'GRADE' button.";
}
exit();
}
?>