-
Notifications
You must be signed in to change notification settings - Fork 1
/
leaderboards.php
142 lines (140 loc) · 5.03 KB
/
leaderboards.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="main.css">
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<title>HACKBOX MAIN</title>
</head>
<?php include 'header3.php';?>
<?php include 'footer.php';?>
<body>
<h1>LEADERBOARDS</h1>
<?php
include("connection.php");
if(isset($_SESSION['userName'])){
?>
<div style="text-align:center;">
<form method="post">
<input class="playAgainBtn" type="submit" name="play" value="Play">
<p>This will reset your progress, your best time will be kept.</p>
<?php
if(isset($_POST['play'])){
$SQLstring = "UPDATE " . $db_table . " SET currentlevel='0',endTime='0000-00-00 00:00:00' WHERE userName='".$_SESSION['userName']."'";
if ($stmt = mysqli_prepare($DBConnect, $SQLstring)) {
$QueryResult = mysqli_stmt_execute($stmt);
if ($QueryResult === FALSE) {
$errorMsg = "<span><p>Unable to execute the query.</p>"
. "<p>Error code "
. mysqli_errno($DBConnect)
. ": "
. mysqli_error($DBConnect)
. "</p></span>";}
//Clean up the $stmt after use
mysqli_stmt_close($stmt);
} else {
$errorMsg = "<span><p>Unable to execute the query.</p>"
. "<p>Error code "
. mysqli_errno($DBConnect)
. ": "
. mysqli_error($DBConnect)
. "</p></span>";
}
header("Location: story0.php");
}
}
?>
</form>
</div>
<table>
<tr>
<th>Username</th>
<th>Best Time(hh/mm/ss)</th>
</tr>
<?php
$SQLstring = "SELECT userName,bestTime,TIMEDIFF(endTime, startTime) FROM " . $db_table;
if ($stmt = mysqli_prepare($DBConnect, $SQLstring)) {
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt,$userName,$bestTime,$tempTime);
mysqli_stmt_store_result($stmt);
if ($stmt === FALSE) {
$errorMsg = "<span><p>Unable to execute the query.</p>"
. "<p>Error code "
. mysqli_errno($DBConnect)
. ": "
. mysqli_error($DBConnect)
. "</p></span>";
} else {
while (mysqli_stmt_fetch($stmt)) {
$SQLstring = "UPDATE " . $db_table . " SET bestTime='".max($tempTime,$bestTime)."' WHERE userName='".$userName."'";
if ($stmtup = mysqli_prepare($DBConnect, $SQLstring)) {
$QueryResult = mysqli_stmt_execute($stmtup);
if ($QueryResult === FALSE) {
$errorMsg = "<span><p>Unable to execute the query.</p>"
. "<p>Error code "
. mysqli_errno($DBConnect)
. ": "
. mysqli_error($DBConnect)
. "</p></span>";}
//Clean up the $stmt after use
mysqli_stmt_close($stmtup);
} else {
$errorMsg = "<span><p>Unable to execute the query.</p>"
. "<p>Error code "
. mysqli_errno($DBConnect)
. ": "
. mysqli_error($DBConnect)
. "</p></span>";
}
}
}
//Clean up the $stmt after use
mysqli_stmt_close($stmt);
} else {
$errorMsg = "<span><p>Unable to execute the query.</p>"
. "<p>Error code "
. mysqli_errno($DBConnect)
. ": "
. mysqli_error($DBConnect)
. "</p></span>";
}
$SQLstring = "SELECT userName,bestTime FROM " . $db_table." ORDER BY bestTime ASC";
if ($stmt = mysqli_prepare($DBConnect, $SQLstring)) {
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $userName,$bestTime);
mysqli_stmt_store_result($stmt);
if ($stmt === FALSE) {
$errorMsg = "<span><p>Unable to execute the query.</p>"
. "<p>Error code "
. mysqli_errno($DBConnect)
. ": "
. mysqli_error($DBConnect)
. "</p></span>";
} else {
while (mysqli_stmt_fetch($stmt)) {
if($bestTime!="00:00:00"){
echo '<tr>
<td>' . $userName . '</td>
<td>' . $bestTime . '</td>
</tr>';
}
}
}
//Clean up the $stmt after use
mysqli_stmt_close($stmt);
} else {
$errorMsg = "<span><p>Unable to execute the query.</p>"
. "<p>Error code "
. mysqli_errno($DBConnect)
. ": "
. mysqli_error($DBConnect)
. "</p></span>";
}
mysqli_close($DBConnect);
?>
</table>
<div class="errorDiv"><?php echo $errorMsg ?></div>
</body>
</html>