I need to get a balance variable out from a table and insert it back to the same table to different value, i am not sure am making it right as SOL is asking me to check the right syntax to use.
This is my full php script
<?php
// Connects to the database
$db = mysql_connect("$Sname","$Uname","$Pname") or die("Could not connect to the Database.");
$select = mysql_select_db("$Dname") or die("Could not select the Database.");
//Converts form values to simple variables
if ($_POST['submitButton']) {
$amount = $_POST['amount'];
$today = date("d/m/Y");
$time = date("h:i A");
$sql = "SELECT * FROM $UUname WHERE full='".$amount."'";
$result = mysql_query($sql) or die(mysql_error());
$num_return = mysql_num_rows($result);
if ($num_return == 1){
// inserts the values into the DB
mysql_query("UPDATE $TATname SET date='".$today."', time='".$time."', amount='".$amount."' WHERE user='{$_SESSION['user']}'");
$user = "{$_SESSION['user']}";
// get credits
$query = mysql_query("SELECT SUM(credit) FROM $UUname WHERE user='".$user."'");
$credit = mysql_result($query, 0);
// get debits
$query = mysql_query("SELECT SUM(debit) FROM $UUname WHERE user='".$user."'");
$debit = mysql_result($query, 0);
$bal = $credit - $debit;
$query = "UPDATE $UUname SET full='".$bal."'";
$update = mysql_query($query) or die(mysql_error());
header("Location: successful.php");
exit;
}
else
{
echo "Insufficient Funds";
}
}
?>
Please what is the right syntax to use on that last line, or what is the right way for me to do this, because i want to tell users that they have insufficient balance when they try to make a transfer.