<?php
	session_start();
	include"../../connect/db.php"; 

	if( isset($_POST['trans']) ){
		$trans = $_POST['trans'];
	//	$sql = mysqli_query($con,"DELETE FROM transactions WHERE trans_id = '$trans' ");

		
			$ayo = mysqli_query($con, "SELECT * FROM transactions WHERE trans_id = '$trans' " );

		$row = mysqli_fetch_assoc($ayo);
	
	
    $amount = 	$row['amount'];
    $user = 	$row['user'];
	
	$ayo22 = mysqli_query($con, "SELECT * FROM users WHERE account_num = '$user' " );

		$saw = mysqli_fetch_assoc($ayo22);
	
	
	$balance = $saw['checking_balance'];
	
	
	
	$new_bal = $balance - $amount;
	
	
		       $query = mysqli_query($con,"UPDATE users SET checking_balance = '$new_bal' WHERE account_num = '$user'  ");
			   $sql = mysqli_query($con,"DELETE FROM transactions WHERE trans_id = '$trans' ");

		
		

		if( $sql ){
			echo "success";
		}
		else{
			echo mysqli_error($con);
		}
 	}


?>		