Hello everyone! I have this issue since yesterday and I can’t still figure it out. I subtract the current load balance and ticket price but I always got a wrong result. Like for instance, the current load balance is 1000 and the ticket price is 54, the difference must be 946 but I always got 622 which is 7x from the ticket price. Can you please check my algorithm and tell me what’s wrong.
This is my source code:
$conn = mysqli_connect($host,$username,$password,$dbname);
$sel = mysqli_query($conn,"SELECT * FROM ticket WHERE Cus_IDNum='$IDNum' AND Bus_Plate_Number='$PlateNum' AND Tk_Sch_Date = CURRENT_DATE()");
while ($rows=mysqli_fetch_array($sel))
{
$Tk_Stat = $rows['Tk_Stat'];
$Tk_Price = $rows['Tk_Price'];
if($Tk_Stat = "UNPAID")
{
$sel2 = mysqli_query($conn,"SELECT * FROM customers WHERE Cus_IDNum='$IDNum'");
while ($rows=mysqli_fetch_array($sel2))
{
$currbal = $rows['Cus_Loadbal'];
if($currbal > $Tk_Price)
{
$totalbal = $currbal - $Tk_Price;
$upd = mysqli_query($conn,"UPDATE ticket SET Tk_Stat = 'PAID' WHERE Cus_IDNum ='$IDNum'");
if($upd)
{
$upd2 = mysqli_query($conn,"UPDATE customers SET Cus_Loadbal = '$totalbal' WHERE Cus_IDNum ='$IDNum'");
if($upd2)
{
$upd3 = mysqli_query($conn,"UPDATE qrcode SET Cus_Loadbal = '$totalbal' WHERE Cus_IDNum ='$IDNum'");
if($upd3)
{
print "1";
}
}
}
}
else
{
print "0";
}
}
}
else if($Tk_Stat = "PAID")
{
print "1";
}
}
If you found something let me know. Thanks in advance