i want to update a single row multiple time. when i update it from one cell it update successfully but when i update it from two cell one of them updated while another want is not.
the MYSQL Table Registration is:
CREATE TABLE `registration` (
`Reg_id` int(11) NOT NULL AUTO_INCREMENT,
`Arrears` int(10) NOT NULL,
`Current_Bill` varchar(20) NOT NULL,
`Current_Surcharge` varchar(20) NOT NULL,
PRIMARY KEY (`Reg_id`),
KEY `Reg_id` (`Reg_id`)
) ENGINE=InnoDB AUTO_INCREMENT=66 DEFAULT CHARSET=latin1;
when i update Arrears
from Current_Bill
and update Current_Bill
to 0
. it works.
but when i update Arrears
from Current_Bill
and update Current_Bill
to 0
and update Arrears
from Current_Surcharge
and Current_Surcharge
to 0
then Current_Surcharge
is updating to Arrears
and Current_Surcharge
updating to 0
and also Current_Bill
Updating to 0
but Arrears
can not be updated from Current_Bill
The PHP Code Is:
<?php
include("Database/connection.php");
$sql = "SELECT * FROM registration,billing_month WHERE Bill_id=(SELECT MAX(Bill_id) FROM billing_month)";
$result = $link->query($sql);
while($row = $result->fetch_assoc())
{
$currentsurcharge = $row['Current_Surcharge'];
$currentbill = $row['Current_Bill'];
$arrears = $row['Arrears'];
$updatearrearsfromcurrentbill = $arrears + $currentbill;
$updatecurrentbilltozero = 0;
$updatearrearsfromcurrentsurcharge = $arrears + $currentsurcharge;
$updatecurrentsurchargetozero = 0;
if (strtotime(date('Y-m-d')) > strtotime($duedate))
{
// thid query is not working while the other
// Update Arrears From Current Bill when Bill Is Not Pay On Due Date
$sql_update5 = "UPDATE `registration` SET `Arrears`= $updatearrearsfromcurrentbill WHERE `Reg_id` = $regid";
// Update Current Bill To Zero
$sql_update6 = "UPDATE `registration` SET `Current_Bill`= $updatecurrentbilltozero WHERE `Reg_id` = $regid";
// Update Arrears From Current Surcharge when Bill is not pay on due date
$sql_update7 = "UPDATE `registration` SET `Arrears`= $updatearrearsfromcurrentsurcharge WHERE `Reg_id` = $regid";
// Update Current Surcharge to Zero
$sql_update8 = "UPDATE `registration` SET `Current_Surcharge` = $updatecurrentsurchargetozero WHERE `Reg_id` = $regid";
mysqli_query($link, $sql_update5);
mysqli_query($link, $sql_update6);
mysqli_query($link, $sql_update7);
mysqli_query($link, $sql_update8);
}
}
?>