add a condition before query is executed
i want to make sure that the balance in account is sufficient before mysqli insert query is executed. i want to compare amount from form to available balance.
<?php require_once('Connections/transaction.php'); ?>
<?php require_once('webassist/mysqli/queryobj.php'); ?>
<?php
$amt = $_POST['debit'];
$bal = "SELECT (SUM(credit) - SUM(debit)) AS balance FROM transaction WHERE account_no = '".$_SESSION['account_no']."' ";
if($debit < $bal) {
header('Location:TransferFund.php?amount=insufficient' ));
exit();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$InsertQuery = new WA_MySQLi_Query($XtremBANK_i);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`transaction`";
$InsertQuery->bindColumn("account_no", "i", "".$_SESSION['account_no'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("trans_date", "t", "", "WA_CURRENT_TIMESTAMP");
$InsertQuery->bindColumn("reference", "s", "".((isset($_POST["reference"]))?$_POST["reference"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("credit", "s", "0.00", "WA_DEFAULT");
$InsertQuery->bindColumn("debit", "s", "".((isset($_POST["debit"]))?$_POST["debit"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("beneficiary_id", "i", "".((isset($_POST["beneficiary_id"]))?$_POST["beneficiary_id"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("trans_type", "s", "".((isset($_POST["trans_type"]))?$_POST["trans_type"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("status", "s", "".((isset($_POST["status"]))?$_POST["status"]:"") ."", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "../../success.php";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>