<?php
$user =mysqli_query($conn,"SELECT * FROM `tb_user` WHERE user = '".$_SESSION['user']."'") or die (mysqli_error());
$u = mysqli_fetch_array($user);
$externalPlayerId = $u['extplayer'];
$sql_255 = mysqli_query($conn, "SELECT * FROM `tb_apigames` WHERE cuid = 1") or die(mysqli_error($conn));
$s255 = mysqli_fetch_array($sql_255);
            
$bal = $kingisback->getBalance($externalPlayerId);
if ((int)$bal['status'] === 200) {
    $getBalanceResponse = $bal['data']['balance'] ?? 0;
} else {
    $getBalanceResponse = 0;
}

// Update balance in database menggunakan mysqli_query biasa
$query = "UPDATE tb_balance SET active = '$getBalanceResponse' WHERE userID = '$userID'";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
?>