last
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
<?php
|
||||
session_start();
|
||||
$conn = new mysqli("localhost", "root", "", "dodge_game");
|
||||
@@ -22,3 +23,29 @@ if ($check->num_rows > 0) {
|
||||
|
||||
echo "OK";
|
||||
?>
|
||||
=======
|
||||
<?php
|
||||
session_start();
|
||||
$conn = new mysqli("localhost", "root", "", "dodge_game");
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("DB Error: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
$username = $_POST['username'];
|
||||
$score = intval($_POST['score']);
|
||||
|
||||
// cek jika user sudah punya skor sebelumnya
|
||||
$check = $conn->query("SELECT * FROM leaderboard WHERE username='$username'");
|
||||
|
||||
if ($check->num_rows > 0) {
|
||||
// update jika score baru lebih tinggi
|
||||
$conn->query("UPDATE leaderboard SET score=GREATEST(score, $score) WHERE username='$username'");
|
||||
} else {
|
||||
// insert jika belum ada
|
||||
$conn->query("INSERT INTO leaderboard (username, score) VALUES ('$username', $score)");
|
||||
}
|
||||
|
||||
echo "OK";
|
||||
?>
|
||||
>>>>>>> 720425e3f38951553731cb9aae9a4c9a34f6c2b4
|
||||
|
||||
Reference in New Issue
Block a user