我需要从表中取出一个平衡变量并将其插入到同一个表中以不同的值,我不确定是否正确,因为 SOL 要求我检查要使用的正确语法。
这是我的完整 php 脚本
<?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";
}
}
?>
请在最后一行使用什么正确的语法,或者我这样做的正确方法是什么,因为我想告诉用户他们在尝试进行转账时余额不足。