add 1 month to date

1Tsme1941

Member
ok guys, another learning experience....I want to add 1 month to a duedate and update. How to include:

(SET duedate = DATE_ADD(duedate, INTERVAL 1 month )

into this:

$sql = "UPDATE payfile SET
amtpaid=?, duedate=?, prevbal=?, latechg=?, secdep=?, damage=?, courtcost=?, nsf=?, hudpay=?, datepaid=?, paidsum=?
WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("dsdddddddsdi", $amtpaid, $duedate, $prevbal, $latechg, $secdep, $damage, $courtcost,
$nsf, $hudpay, $datepaid, $paidsum, $id);
$stmt->execute();
 

Cromewell

Administrator
Staff member
Probably like this:
$sql = "UPDATE payfile SET
amtpaid=?, duedate=DATE_ADD(?, INTERVAL 1 month), prevbal=?, latechg=?, secdep=?, damage=?, courtcost=?, nsf=?, hudpay=?, datepaid=?, paidsum=?
WHERE id=?";

I have not tested this, but syntax looks ok to me.
 

1Tsme1941

Member
Thanks friend for contributing. I tried your suggestion. Doesn't seem to update but since I've fought
the issue of defining the variables negating the results for months, my only certainty is that if my
definitions weren't changing the table values the problems would go "POOF".

$receiptno=0; causes the issue on line 29

I define numbers $amtdue=0.00; Obviously causes "owed" on line 38 to be "0", in turn my if statement
goes from line 45 to line 48. That is why I echo "530.00" on line 119.

the relevant code:
$unit = $_POST['unit'];
$amtpaid = $_POST['amtpaid']; // ********************************** is 530.00
$hudpay = $_POST['hudpay'];
$datepaid = $_POST['datepaid'];

$amtdue = 0; // ****************************************
$duedate="duedate";
$prevbal=0.;
$latechg=0.;
$secdep=0.;
$damage=0.;
$courtcost=0.;
$nsf=0.;
$paidsum=0.;
$receiptno=0; // ****************************************

$sql = "UPDATE numbers SET receiptno = receiptno+1 WHERE id=1"; // ************ updates
if ($conn->query($sql) !== true) { echo "Failed to update receiptno"; }
else { echo " "; }
echo "receipt # is " .$receiptno . "<br>"; // line 29

// Attempt select query execution
$result = mysqli_query($conn,"SELECT * FROM payfile Where amtpaid = '0.00'");
$row= mysqli_fetch_array($result);

$today = date("Y-m-d");
if ($duedate < $today){ $latechg = $latechg + 10.00; }

$owed = $amtdue + $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf; // line 38

/* if no payment or partial payment */
if ($amtpaid < $owed)
{ $prevbal = $owed - $amtpaid; $secdep = 0.00; $damage = 0.00; $courtcost = 0.00; $nsf = 0.00;}

/* if payment = amtdue clear due */ // ****** this event
elseif ($amtpaid == $owed)
{ $prevbal = 0.00; $secdep = 0.00; $damage = 0.00; $courtcost = 0.00; $nsf = 0.00; }

/* if over-payment subtract over-payment from prevbal field */
elseif ($amtpaid > $owed )
{ $prevbal = $amtpaid - $owed; $secdep = 0.00; $damage = 0.00; $courtcost = 0.00; $nsf = 0.00; }

$amtpaid = $paidsum;

$sql = "UPDATE payfile SET
amtpaid=?, duedate=DATE_ADD(?, INTERVAL 1 month), prevbal=?, latechg=?, secdep=?, damage=?, courtcost=?, nsf=?, hudpay=?, datepaid=?, paidsum=?
WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("dsdddddddsdi", $amtpaid, $duedate, $prevbal, $latechg, $secdep, $damage, $courtcost,
$nsf, $hudpay, $datepaid, $paidsum, $id);
$stmt->execute();
?>
Amount due: <?php echo $prevbal; ?><br> // ********************* this IS 0.00 but displays 530.00 - line 119
 
Top