Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: mysqli prepared update  (Read 79169 times)

0 Members and 1 Guest are viewing this topic.

guitarzRus

    Topic Starter


    Rookie

    • Experience: Experienced
    • OS: Windows 7
    mysqli prepared update
    « on: October 25, 2021, 06:15:14 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";  // ****************************
    ?>

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