From d27b2bf3f99434c64c5a04c773bbb8302af4d961 Mon Sep 17 00:00:00 2001 From: angelicatesvara07-crypto Date: Mon, 15 Dec 2025 19:57:21 +0700 Subject: [PATCH] Leaderboard Fix --- Sudoku.php | 16 +++++--- leaderboard.php | 19 +++------- save_scoee.php | 13 ------- save_score.php | 98 +++++++++++-------------------------------------- 4 files changed, 38 insertions(+), 108 deletions(-) delete mode 100644 save_scoee.php diff --git a/Sudoku.php b/Sudoku.php index 961570a..ff576cf 100644 --- a/Sudoku.php +++ b/Sudoku.php @@ -793,14 +793,18 @@ if (!isset($_SESSION['username'])) { } } - function saveScore() { - fetch("save_score.php", { +function saveScore() { + fetch("/kelompok03-codeplay-Angelica-Rinaldo-Farrel/save_score.php", { method: "POST", - headers: { "Content-Type": "application/x-www-form-urlencoded" }, - body: `difficulty=${currentDifficulty}&time=${secondsElapsed}` - }); + headers: { + "Content-Type": "application/x-www-form-urlencoded" + }, + body: 'difficulty=${currentDifficulty}&time=${secondsElapsed}' + }) + .then(res => res.text()) + .then(data => console.log("SAVE SCORE:", data)) + .catch(err => console.error(err)); } - \ No newline at end of file diff --git a/leaderboard.php b/leaderboard.php index b5f0958..df4f5e3 100644 --- a/leaderboard.php +++ b/leaderboard.php @@ -1,11 +1,6 @@ query($sql); +$stmt = $conn->query($sql); +$data = $stmt->fetchAll(); ?> - - +if (!isset($_POST['difficulty'], $_POST['time'])) { + echo "NO_POST"; + exit; +} -

🏆 Leaderboard Sudoku

+$username ='testuser'; +$difficulty = $_POST['difficulty']; +$time = (int) $_POST['time']; - - - - - - +$sql = "INSERT INTO leaderboard_sudoku + (username, difficulty, time_seconds) + VALUES (:username, :difficulty, :time)"; -fetch(PDO::FETCH_ASSOC)): ?> - - - - - - +$stmt = $conn->prepare($sql); +$stmt->execute([ + ':username' => $username, + ':difficulty' => $difficulty, + ':time' => $time +]); -
UsernameDifficultyTime (mm:ss)
- -
- -⬅ Kembali - - - +echo "SUCCESS"; \ No newline at end of file