diff --git a/gamefix.php b/gamefix.php new file mode 100644 index 0000000..afc6288 --- /dev/null +++ b/gamefix.php @@ -0,0 +1,251 @@ +'error','message'=>'Jumlah top up tidak valid.']); + exit; + } + + // UPDATE SALDO (BANK) + $sql = "UPDATE users SET bank = bank + ? WHERE id = ?"; + $stmt = mysqli_prepare($conn, $sql); + mysqli_stmt_bind_param($stmt, "ii", $amount, $user_id); + mysqli_stmt_execute($stmt); + mysqli_stmt_close($stmt); + + // Ambil saldo baru + $sql2 = "SELECT bank FROM users WHERE id = ?"; + $stmt2 = mysqli_prepare($conn, $sql2); + mysqli_stmt_bind_param($stmt2, "i", $user_id); + mysqli_stmt_execute($stmt2); + $result = mysqli_stmt_get_result($stmt2); + $row = mysqli_fetch_assoc($result); + mysqli_stmt_close($stmt2); + + $_SESSION['bank'] = intval($row['bank']); + + echo json_encode([ + 'status' => 'ok', + 'bank' => $_SESSION['bank'], + 'message' => 'Top up berhasil.' + ]); + exit; + } + + // ========= SET BANK (saldo game win/lose) =========== + if ($action === 'set_balance') { + $newBank = intval($_POST['balance']); + if ($newBank < 0) { + echo json_encode(['status'=>'error','message'=>'Bank tidak valid']); + exit; + } + + $sql = "UPDATE users SET bank = ? WHERE id = ?"; + $stmt = mysqli_prepare($conn, $sql); + mysqli_stmt_bind_param($stmt, "ii", $newBank, $user_id); + mysqli_stmt_execute($stmt); + mysqli_stmt_close($stmt); + + $_SESSION['bank'] = $newBank; + + echo json_encode(['status'=>'ok','bank'=>$newBank]); + exit; + } + + echo json_encode(['status'=>'error','message'=>'Action tidak dikenal']); + exit; +} + +// ============================= +// LOAD USER DATA NORMAL +// ============================= +$user_id = intval($_SESSION['user_id']); + +$sql = "SELECT username, bank FROM users WHERE id = ?"; +$stmt = mysqli_prepare($conn, $sql); +mysqli_stmt_bind_param($stmt, "i", $user_id); +mysqli_stmt_execute($stmt); +$res = mysqli_stmt_get_result($stmt); +$user = mysqli_fetch_assoc($res); +mysqli_stmt_close($stmt); + +if (!$user) { + session_destroy(); + header("Location: loginn.php"); + exit; +} + +$_SESSION['username'] = $user['username']; +$_SESSION['bank'] = intval($user['bank']); + +$username = htmlspecialchars($_SESSION['username']); +$bank = intval($_SESSION['bank']); +?> + + +
+ +