Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Generic User Avatar

mysqli prepared update


  • Please log in to reply
No replies to this topic

#1 guitarzRus

guitarzRus

  •  Avatar image
  • Members
  • 30 posts
  • OFFLINE
  •  
  • Local time:01:49 PM

Posted 25 October 2021 - 07:06 PM

Hi guys, I believe I"ve correctly coded this and think I'm so close.
 
I enter my HTML form:
                                record a payment
Unit: apt1  Amt paid: 530.00  Hudpay: 0.00  Date paid: - yyyy-mm-dd:  2021-07-10
---------------------------------------------------------------------------------
and get this result:
receiptno updated successfully 0 payfile updated successfully
For:
tenant paying: apt1 - Amount paid: 530.00 - Date paid: 2021-07-10 - Amount due: 530
-----------------------------------------------------------------------------------
The numbers table IS updated. The receiptno is 1310 but is displayed as 0 ??. The payfile IS NOT updated ??
The amount due should display as 0.00. The ? I've had all along: is "$receiptno = 0;" a way to define
it as numeric and does it also define it as having 0 value? I leave it out, it's undefined, put it in
the table value of 1310 is replaced with 0 ??
In the calcs:
elseif ($amtpaid == $owed)
{ $prevbal = 0.00; }
   is true, yet "Amount due: <?php echo $prevbal; ?>" displays 530.00??
----------------------------------------------------------------------------------
the code:

$unit = $_POST['unit'];
$amtpaid = $_POST['amtpaid']; // **********************************
$hudpay = $_POST['hudpay'];
$datepaid = $_POST['datepaid'];

$amtdue = 0.00;  // ****************************************
$prevbal=0.00;
$latechg=0.00;
$secdep=0.00;
$damage=0.00;
$courtcost=0.00;
$nsf=0.00;
$paidsum=0.00;
$comments="";
$receiptno=0;   // ****************************************
$id="id";

$sql = "UPDATE numbers SET receiptno =receiptno+1 WHERE id=1";  // ****************************
if ($conn->query($sql) === TRUE) { echo "receiptno updated successfully"; }  
else { echo "Error updating record: " . $conn->error; }
echo $receiptno; // ****************************

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

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

/* if no payment or partial payment, add $10 to latechg field and amount not paid to prevbal field */
if ($amtpaid < $owed)
{ $latechg = $latechg + 10.00; $prevbal = $owed - $amtpaid; }

/* if payment = amtdue clear due */  // ****************************** this event
elseif ($amtpaid == $owed)
{ $prevbal = 0.00; $latechg = 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; $latechg = 0.00; $secdep = 0.00; $damage = 0.00; $courtcost = 0.00; $nsf = 0.00; }

$amtpaid = $paidsum;
                                                      
$sql = "UPDATE payfile SET
amtpaid=?, prevbal=?, latechg=?, secdep=?, damage=?, courtcost=?, nsf=?, hudpay=?, datepaid=?, paidsum=?, comments=?
WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ddddddddsdsi", $amtpaid, $prevbal, $latechg, $secdep, $damage, $courtcost, $nsf, $hudpay, $datepaid,  $paidsum,
$comments, $id);
$stmt->execute();
echo "payfile updated successfully";  // ****************************
?>

<b> tenant paying: <?php echo $_POST["unit"]; ?> -
Amount paid: <?php echo $_POST["amtpaid"]; ?> -
Date paid: <?php echo $_POST["datepaid"]; ?> -
Amount due: <?php echo $prevbal; ?><br>  /* *****************************

 



BC AdBot (Login to Remove)

 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users