-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighscores.php
More file actions
37 lines (29 loc) · 1.14 KB
/
Copy pathhighscores.php
File metadata and controls
37 lines (29 loc) · 1.14 KB
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
<?php
$servername = "localhost";
$username = "scramble_user";
$password = "scramble_pass";
$db = "scramble_db";
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error) {
die("Oops - something went wrong: " . $conn->connect_error);
}
$score = $_POST['score'];
$level = $_POST['level'];
$initials = $_POST['initials'];
$email_address = $_POST['email_address'];
$ip = $_SERVER['REMOTE_ADDR'];
$time_stamp = date("c");
// Using prepared statement to prevent SQL injection
if ($stmt = $conn->prepare("INSERT INTO high_scores (score, level, initials, email_address, ip_address, time_stamp) VALUES (?, ?, ?, ?, ?, ?)")) {
$stmt->bind_param("ssssss", $score, $level, $initials, $email_address, $ip, $time_stamp);
$stmt->execute();
}
$sql = "SELECT initials, score FROM high_scores ORDER BY score DESC LIMIT 10";
$result = $conn->query($sql);
echo "<table>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["initials"] . "</td><td>" . $row["score"] . "</td></tr>";
}
echo "</table>";
$conn->close();
?>