<?php
ob_start();
session_start();
date_default_timezone_set("Asia/Jakarta");
include('config/koneksi.php');
include('config/class_softgaming.php');
$sid = session_id();

$user = mysqli_query($conn, "SELECT * FROM tb_user WHERE username = '" . $_SESSION['user'] . "'") or die(mysqli_error());
$u = mysqli_fetch_array($user);

$users = $u['username']; 
$id_user = $u['cuid'];
$userID = $u['cuid'];

$balance = $WL->getBalance($users);
 
 if($balance['status'] == "success"){
 $balanceUser = $balance['user']['balance'];
 
 if(mysqli_query($conn, "UPDATE tb_balance SET active = '$balanceUser' WHERE userID = '$userID'") == true){

 $formatted_balance = number_format($balanceUser, 0, ',', '.');
 echo $formatted_balance;
 } else {
 echo "Terjadi kesalahan dalam memperbarui saldo ke dalam tabel tb_balance: " . mysqli_error($conn);
 }
} else { 
echo $balance['msg'];
}
?>