469,602 Members | 1,727 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

defining variables as numeric

6
Hi guys,
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:
receipt # is 0
For:
tenant paying: apt1 - Amount paid: 530.00 - Date paid: 2021-07-10 - Amount due: 530
-----------------------------------------------------------------------------------
My program is to accept a payment and print a receipt displaying the receiptno and amount due
(prevbal determined by calcs) while showing a pic of the account's biz.
The receipt looks fine but the receiptno is 1310, displayed as 0 ??. My question I can't get answered: 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 and the table value of 1310 is replaced with 0.
Because of this:
$owed = $amtdue + $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf;
equates to:
$owed = 0.00 + 0.00 + 0.00 + 0.00 + 0.00 + 0.00 + 0.00;
The numbers table IS updated.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>make payment and print receipt</title>
  4. </head>
  5. <body><center>
  6. <?php
  7. // Include config file
  8. include 'getprerentdb.php';
  9.  
  10. $unit = $_POST['unit'];
  11. $amtpaid = $_POST['amtpaid']; // ********************************** is 530.00
  12. $hudpay = $_POST['hudpay'];
  13. $datepaid = $_POST['datepaid'];
  14.  
  15. $amtdue = 0.00; // *******  
  16. $prevbal=0.00;
  17. $latechg=0.;
  18. $secdep=0.00;
  19. $damage=0.00;
  20. $courtcost=0.00;
  21. $nsf=0.00;
  22. $paidsum=0.00;
  23. $comments="comments";
  24. $receiptno=0; // *******
  25.  
  26. $sql = "UPDATE numbers SET receiptno = receiptno+1 WHERE id=1";  // ************ updates
  27. if ($conn->query($sql) !== true) { echo "Failed to update receiptno"; }
  28. else { echo " "; }
  29. echo "receipt # is " .$receiptno . "<br>";
  30.  
  31. // Attempt select query execution
  32. $result = mysqli_query($conn,"SELECT * FROM payfile"); 
  33. $row= mysqli_fetch_array($result);
  34.  
  35. $owed =  $amtdue +  $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf;
  36.  
  37. /* if no payment or partial payment, add $10 to latechg field and amount not paid to prevbal field */
  38. if ($amtpaid < $owed)
  39. { $latechg = $latechg + 10.00; $prevbal = $owed - $amtpaid; }
  40.  
  41. /* if payment = amtdue clear due */  // ****************************** this event
  42. if ($amtpaid == $owed)
  43. { $prevbal = 0.00; $latechg = 0.00; $secdep = 0.00; $damage = 0.00; $courtcost = 0.00; $nsf = 0.00; }
  44.  
  45. /* if over-payment subtract over-payment from prevbal field */
  46. if ($amtpaid > $owed )
  47. { $prevbal = $amtpaid - $owed; $latechg = 0.00; $secdep = 0.00; $damage = 0.00; $courtcost = 0.00; $nsf = 0.00; }
  48.  
  49. $paidsum=$amtpaid;
  50.  
  51. $sql = "UPDATE payfile SET
  52. amtpaid=?, late=?, hudpay=?, paidsum=?, datepaid=?, prevbal=?, latechg=?, secdep=?, damage=?, courtcost=?,
  53.  nsf=?, comments=? WHERE id=?"; 
  54. $stmt = $conn->prepare($sql);
  55. $stmt->bind_param("dsddsddddddsi", $amtpaid, $late, $hudpay, $paidsum, $datepaid, $prevbal, $latechg, $secdep, $damage, $courtcost, 
  56. $nsf, $comments, $id);
  57. $stmt->execute();
  58. ?>
  59.                     more code
  60. <b> tenant paying: <?php echo $_POST["unit"]; ?> -
  61. Amount paid: <?php echo $_POST["amtpaid"]; ?> -
  62. Date paid: <?php echo $_POST["datepaid"]; ?> -
  63. Amount due: <?php echo $prevbal; ?><br> // ********************* this IS 0.00 but displays 530.00  line 116
  64. <input type="text" size = 75 STYLE="color: #000000; background-color: #D4AAFF;" name="sign" value="Sign here">
  65. <input type="text" size = 25 STYLE="color: #000000; background-color: #D4AAFF;" name="thanks" value="We Thank You"><br>
  66. </b></center></body></html>
The payfile IS NOT updated ??
4 Weeks Ago #1
1 7541
dev7060
519 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>make payment and print receipt</title>
  4. </head>
  5. <body><center>
  6. <?php
  7. // Include config file
  8. include 'getprerentdb.php';
  9.  
  10. $unit = $_POST['unit'];
  11. $amtpaid = $_POST['amtpaid']; // ********************************** is 530.00
  12. $hudpay = $_POST['hudpay'];
  13. $datepaid = $_POST['datepaid'];
  14.  
  15. $amtdue = 0.00; // *******  
  16. $prevbal=0.00;
  17. $latechg=0.;
  18. $secdep=0.00;
  19. $damage=0.00;
  20. $courtcost=0.00;
  21. $nsf=0.00;
  22. $paidsum=0.00;
  23. $comments="comments";
  24. $receiptno=0; // *******
  25.  
  26. $sql = "UPDATE numbers SET receiptno = receiptno+1 WHERE id=1";  // ************ updates
  27. if ($conn->query($sql) !== true) { echo "Failed to update receiptno"; }
  28. else { echo " "; }
  29. echo "receipt # is " .$receiptno . "<br>";
  30.  
  31. // Attempt select query execution
  32. $result = mysqli_query($conn,"SELECT * FROM payfile"); 
  33. $row= mysqli_fetch_array($result);
  34.  
  35. $owed =  $amtdue +  $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf;
  36.  
  37. /* if no payment or partial payment, add $10 to latechg field and amount not paid to prevbal field */
  38. if ($amtpaid < $owed)
  39. { $latechg = $latechg + 10.00; $prevbal = $owed - $amtpaid; }
  40.  
  41. /* if payment = amtdue clear due */  // ****************************** this event
  42. if ($amtpaid == $owed)
  43. { $prevbal = 0.00; $latechg = 0.00; $secdep = 0.00; $damage = 0.00; $courtcost = 0.00; $nsf = 0.00; }
  44.  
  45. /* if over-payment subtract over-payment from prevbal field */
  46. if ($amtpaid > $owed )
  47. { $prevbal = $amtpaid - $owed; $latechg = 0.00; $secdep = 0.00; $damage = 0.00; $courtcost = 0.00; $nsf = 0.00; }
  48.  
  49. $paidsum=$amtpaid;
  50.  
  51. $sql = "UPDATE payfile SET
  52. amtpaid=?, late=?, hudpay=?, paidsum=?, datepaid=?, prevbal=?, latechg=?, secdep=?, damage=?, courtcost=?,
  53.  nsf=?, comments=? WHERE id=?"; 
  54. $stmt = $conn->prepare($sql);
  55. $stmt->bind_param("dsddsddddddsi", $amtpaid, $late, $hudpay, $paidsum, $datepaid, $prevbal, $latechg, $secdep, $damage, $courtcost, 
  56. $nsf, $comments, $id);
  57. $stmt->execute();
  58. ?>
  59.                     more code
  60. <b> tenant paying: <?php echo $_POST["unit"]; ?> -
  61. Amount paid: <?php echo $_POST["amtpaid"]; ?> -
  62. Date paid: <?php echo $_POST["datepaid"]; ?> -
  63. Amount due: <?php echo $prevbal; ?><br> // ********************* this IS 0.00 but displays 530.00  line 116
  64. <input type="text" size = 75 STYLE="color: #000000; background-color: #D4AAFF;" name="sign" value="Sign here">
  65. <input type="text" size = 25 STYLE="color: #000000; background-color: #D4AAFF;" name="thanks" value="We Thank You"><br>
  66. </b></center></body></html>
My question I can't get answered: is "$receiptno = 0;" a way to define
it as numeric and does it also define it as having 0 value?
PHP is not a strictly typed language.

I leave it out, it's undefined, put it
in and the table value of 1310 is replaced with 0.
Because of this:
$owed = $amtdue + $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf;
equates to:
$owed = 0.00 + 0.00 + 0.00 + 0.00 + 0.00 + 0.00 + 0.00;
The numbers table IS updated.
I don't see the variables updated. You may want to look at the use of lines 32 and 33.
3 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Dominik Kaspar | last post: by
1 post views Thread by Manlio Perillo | last post: by
4 posts views Thread by Andrew | last post: by
6 posts views Thread by Phil Latio | last post: by
7 posts views Thread by Roman Mashak | last post: by
18 posts views Thread by plenty900 | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.