-
Notifications
You must be signed in to change notification settings - Fork 1
/
high_score.php
executable file
·61 lines (51 loc) · 1.16 KB
/
high_score.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
#!/usr/bin/env php
<html>
<head>
<title>High Scores</title>
</head>
<body>
<?php
$seconds = $_GET["seconds"];
$name = $_GET["name"];
if(!$name) {
$name = "Geoff";
}
// Connecting, selecting database
$link = mysql_connect('db.mipsisrisc.com', 'zero_g', 'icadil18')
or die('Could not connect: ' . mysql_error());
mysql_select_db('zero_g') or die('Could not select database');
//TODO: SANITIZE INPUT
if($seconds && $name) {
$query = 'INSERT INTO scores (name, score) VALUES ("'.$name.'", '.$seconds.')';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
}
$query = 'SELECT name, score FROM scores ORDER BY score DESC LIMIT 10';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<?
while ($line = mysql_fetch_array($result, MYSQL_NUM)) {
echo "\t<tr>\n";
echo "\t\t<td>$line[0]</td>\n";
echo "\t\t<td>$line[1] seconds</td>\n";
echo "\t</tr>\n";
}
?>
</tbody>
</table>
<?
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
</body>
</html>