<?php 
ob_start();
session_start();
include("config.php");


$userid=mysqli_real_escape_string($com,$_POST['userid']);
$withdraw=mysqli_real_escape_string($com,$_POST['withdraw']);

 $sqlwithdra = mysqli_query($com,"select * from paymentsetting where id ='1'");
 $withdra_row = mysqli_fetch_array($sqlwithdra);
 $withdra = $withdra_row['withdrawalamount'];

$userid = $_SESSION['frontuserid'];
$sqlwallet = mysqli_query($com,"select * from withdraw_balance where userid ='$userid'");
$wallert_row = mysqli_fetch_assoc($sqlwallet);
$withhdraw_balance = $wallert_row['amount'];

if($withhdraw_balance >= $withdraw)
{
					  
if($withdraw >= $withdra)
{
					  

$today = date("Y-m-d H:i:s");
 
 
$withdrawalsql= mysqli_query($com,"INSERT INTO `withdrawal`(`userid`,`amount`,`status`,`createdate`) 
                                            VALUES ('".$userid."','".$withdraw."','0','".$today."')");

$actiontype="withdraw";
$sql3= mysqli_query($com,"INSERT INTO walletsummery(userid,amount,status,type,actiontype) VALUES ('$userid','$withdraw','0','debit','$actiontype')");

$sqlwallet= mysqli_query($com,"update withdraw_balance set amount = amount - '$withdraw' WHERE userid= '$userid'");	


echo ("<script LANGUAGE='JavaScript'>
    window.alert('Request Submited');
    window.location.href='withdrawal.php';
    </script>");

}else{
   echo ("<script LANGUAGE='JavaScript'>
    window.alert('Somthing Error');
    window.location.href='withdrawal.php';
    </script>"); 
}
}else{
   echo ("<script LANGUAGE='JavaScript'>
    window.alert('Insufficient balance');
    window.location.href='withdrawal.php';
    </script>"); 
}
?>