php - Multiple Update Query -
i have written 2 different codes in php , want merge 1 code because both codes same, update
query different. can 1 me? , second problem if
condition does'nt work why that?
code1:
<?php include("database/connection.php"); $sql = "select * registration,billing_month"; $result = $link->query($sql); while ($row = $result->fetch_assoc()) { $regid = $row['reg_id']; $duedate = $row['bill_due_date']; $currentbill = $row['current_bill']; $arrears = $row['arrears']; $updatearrears = $arrears + $currentbill; if (date('y-m-d') > $duedate) { $sql_update = "update registration set arrears= $updatearrears reg_id = $regid"; if (mysqli_query($link, $sql_update)) { // echo "updated"; } else { // echo "could not updated"; } } } ?>
code2:
<?php include("database/connection.php"); $sql = "select * registration,billing_month"; $result = $link->query($sql); while ($row = $result->fetch_assoc()) { $regid = $row['reg_id']; $billingid = $row['bill_id']; $duedate = $row['bill_due_date']; $currentbill = $row['current_bill']; $updatebill = 0; if (date('y-m-d') > $duedate) { $sql_update = "update registration set current_bill= $updatebill reg_id = $regid"; if (mysqli_query($link, $sql_update)) { // echo "updated"; } else { // echo "could not updated"; } } } ?>
use strtotime() compare data. add quotes in value.
before update database use
$updatebill=mysqli_real_escape_string($link,$updatebill); if (strtotime(date('y-m-d')) > strtotime($duedate)) { $sql_update = "update `registration` set `current_bill`= '".$updatebill ."' `reg_id` = $regid"; }
to check error in page use
ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1);
and prevent query sql injection
Comments
Post a Comment