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