<?php 
ob_start();
session_start();
include("include/connection.php");

$userid=$_SESSION['frontuserid'];
$betamount=$_POST['betamount'];
$gameType=$_POST['gameType'];

$chkwallet=mysqli_query($con,"select amount from tbl_wallet where userid='$userid'");
$chkwalletResult=mysqli_fetch_assoc($chkwallet);
if($chkwalletResult['amount']>=$betamount){
  $sql= mysqli_query($con,"INSERT INTO `tbl_betting` (`userid`,`type`,`amount`) VALUES ('".$userid."','".$gameType."','".$betamount."')");
 
 $walletbalance=wallet($con,'amount',$userid);	
$finalbalanceDebit=$walletbalance-$betamount;	
$sqlwallet= mysqli_query($con,"UPDATE `tbl_wallet` SET `amount` = '".$finalbalanceDebit."' WHERE `userid`= '".$userid."'");	
 echo number_format($finalbalanceDebit,2);
}else{	
echo 'fail';
}
?>