-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.php
74 lines (61 loc) · 2.34 KB
/
game.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
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['nickname'])) {
$servername = "localhost";
$username = "root";
$password = "";
$database = "fetadb";
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$nickname = $_POST['nickname'];
$highScore = $_POST['highScore'];
$checkQuery = "SELECT highScore FROM users WHERE nickname = '$nickname'";
$checkResult = $conn->query($checkQuery);
if ($checkResult->num_rows > 0) {
$row = $checkResult->fetch_assoc();
$existingHighScore = $row["highScore"];
if ($highScore > $existingHighScore) {
$updateQuery = "UPDATE users SET highScore = $highScore WHERE nickname = '$nickname'";
if ($conn->query($updateQuery) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
} else {
echo "Score not higher than existing score, not updated";
}
} else {
$insertQuery = "INSERT INTO users (nickname, highScore) VALUES ('$nickname', '$highScore')";
if ($conn->query($insertQuery) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $insertQuery . "<br>" . $conn->error;
}
}
$conn->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Feta | Game</title>
<link rel="icon" href="src/feta.png" type="image/png">
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<div class="name" data-name><?php echo isset($_SESSION['nickname']) ? $_SESSION['nickname'] : "Name" ?></div>
<div class="world" data-world>
<div class="score" data-score>0</div>
<div class="start-screen" data-start-screen>Press LMB to start</div>
<img src="src/ground.png" class="ground" data-ground>
<img src="src/ground.png" class="ground" data-ground>
<img src="src/mis-idle.png" class="mis" data-mis>
</div>
<script src="script.js" type="module"></script>
</body>
</html>