defining variables as numeric

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bytM3
    New Member
    • May 2021
    • 6

    defining variables as numeric

    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.
    Code:
    <html>
    <head>
    <title>make payment and print receipt</title>
    </head>
    <body><center>
    <?php
    // Include config file
    include 'getprerentdb.php';
    
    $unit = $_POST['unit'];
    $amtpaid = $_POST['amtpaid']; // ********************************** is 530.00
    $hudpay = $_POST['hudpay'];
    $datepaid = $_POST['datepaid'];
    
    $amtdue = 0.00; // *******  
    $prevbal=0.00;
    $latechg=0.;
    $secdep=0.00;
    $damage=0.00;
    $courtcost=0.00;
    $nsf=0.00;
    $paidsum=0.00;
    $comments="comments";
    $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>";
      
    // Attempt select query execution
    $result = mysqli_query($conn,"SELECT * FROM payfile"); 
    $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
    if ($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 */
    if ($amtpaid > $owed )
    { $prevbal = $amtpaid - $owed; $latechg = 0.00; $secdep = 0.00; $damage = 0.00; $courtcost = 0.00; $nsf = 0.00; }
    
    $paidsum=$amtpaid;
    
    $sql = "UPDATE payfile SET
    amtpaid=?, late=?, hudpay=?, paidsum=?, datepaid=?, prevbal=?, latechg=?, secdep=?, damage=?, courtcost=?,
     nsf=?, comments=? WHERE id=?"; 
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("dsddsddddddsi", $amtpaid, $late, $hudpay, $paidsum, $datepaid, $prevbal, $latechg, $secdep, $damage, $courtcost, 
    $nsf, $comments, $id);
    $stmt->execute();
    ?>
                        more code
    <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> // ********************* this IS 0.00 but displays 530.00  line 116
    <input type="text" size = 75 STYLE="color: #000000; background-color: #D4AAFF;" name="sign" value="Sign here">
    <input type="text" size = 25 STYLE="color: #000000; background-color: #D4AAFF;" name="thanks" value="We Thank You"><br>
    </b></center></body></html>
    The payfile IS NOT updated ??
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Code:
    <html>
    <head>
    <title>make payment and print receipt</title>
    </head>
    <body><center>
    <?php
    // Include config file
    include 'getprerentdb.php';
     
    $unit = $_POST['unit'];
    $amtpaid = $_POST['amtpaid']; // ********************************** is 530.00
    $hudpay = $_POST['hudpay'];
    $datepaid = $_POST['datepaid'];
     
    $amtdue = 0.00; // *******  
    $prevbal=0.00;
    $latechg=0.;
    $secdep=0.00;
    $damage=0.00;
    $courtcost=0.00;
    $nsf=0.00;
    $paidsum=0.00;
    $comments="comments";
    $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>";
     
    // Attempt select query execution
    $result = mysqli_query($conn,"SELECT * FROM payfile"); 
    $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
    if ($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 */
    if ($amtpaid > $owed )
    { $prevbal = $amtpaid - $owed; $latechg = 0.00; $secdep = 0.00; $damage = 0.00; $courtcost = 0.00; $nsf = 0.00; }
     
    $paidsum=$amtpaid;
     
    $sql = "UPDATE payfile SET
    amtpaid=?, late=?, hudpay=?, paidsum=?, datepaid=?, prevbal=?, latechg=?, secdep=?, damage=?, courtcost=?,
     nsf=?, comments=? WHERE id=?"; 
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("dsddsddddddsi", $amtpaid, $late, $hudpay, $paidsum, $datepaid, $prevbal, $latechg, $secdep, $damage, $courtcost, 
    $nsf, $comments, $id);
    $stmt->execute();
    ?>
                        more code
    <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> // ********************* this IS 0.00 but displays 530.00  line 116
    <input type="text" size = 75 STYLE="color: #000000; background-color: #D4AAFF;" name="sign" value="Sign here">
    <input type="text" size = 25 STYLE="color: #000000; background-color: #D4AAFF;" name="thanks" value="We Thank You"><br>
    </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.

    Comment

    Working...