-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateDB.php
50 lines (37 loc) · 1.25 KB
/
updateDB.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
<?php
$scoring = array("12", "10", "8", "7", "6", "5", "4", "3", "2", "1");
$user = $_COOKIE["userName"];
include 'db_connection.php';
$con = OpenCon();
$values = $_GET['select'];
$count = 0;
// Checks whether the user is able to vote
$sql = "SELECT voted FROM people WHERE name = '$user'";
$voted = mysqli_query($con, $sql) or die("Connection failed" . $con->connect_error);
$voted = mysqli_fetch_row($voted);
$voted = $voted[0];
if ($voted == 0){
foreach ($values as $a){
// Gets the points for the selected country
$sql = "SELECT points FROM country WHERE country = '$a'";
$points = mysqli_query($con, $sql) or die("Connection failed" . $con->connect_error);
$points = mysqli_fetch_row($points);
$points = $points[0];
// Adds on the points the user has assigned, to the current value in the database
$sql = "UPDATE country
SET points = ($points + $scoring[$count])
WHERE country = '$a';";
// Runs the update query
$con->query($sql);
$count = $count + 1;
}
// Sets the current user to has voted
$sql = "UPDATE `people` SET `voted`= 1 WHERE name = '$user';";
$con->query($sql);
$con->close();
header("Location: submitted.html");
}
else{
header("Location: alreadyVoted.html");
}
?>