<<<<<<< HEAD
<?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";
?>
=======
<?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
