Hi guys, the project is to record a payment from a form, and print a receipt. Prob is no receipt, no balance due, no error message is displayed, the paidday is entered in several records as "pa" and all "amtpaid" are cleared. A little help! ============================== THE CODE: <?php $link = mysqli_connect("localhost", "root", "", "homedb"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } //MySqli Select Query $sql = "select receiptno, custname, custstreet, custemail, custcity, custstate, custzip FROM ctltbl"; $unit=$_POST['unit']; $amtpaid=$_POST['amtpaid']; $paidday=$_POST['paidday']; $id='id'; $unit='unit'; $amtpaid = (int)'amtpaid'; $amtdue = (int)'amtdue'; $prevbal = (int)'prevbal'; $latechg = (int)'latechg'; $secdep = (int)'secdep'; $damage = (int)'damage'; $courtcost = (int)'courtcost'; $nsf = (int)'nsf'; $hudpay = (int)'hudpay'; $paidday = 'paidday'; $due = (int)'due'; $owed = (int)'owed'; $custname = 'custname'; $custstreet = 'custstreet'; $custemail = 'custemail'; $custcity = 'custcity'; $custzip = 'custzip'; $receiptno = (int)'receiptno'; $due = $amtdue + $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf - $hudpay; $owed = $due - $amtpaid; // if no payment or partial payment, add $35 to latechg field and amount not paid to prevbal field if ($amtpaid < $due) { $prevbal = $due - $amtpaid; } // if over-payment subtract over-payment from prevbal field if ($amtpaid > $due) { $prevbal = $amtpaid - $due; } /* Perform a query, check for error */ $sql = "UPDATE paytbl SET amtpaid = '$amtpaid', prevbal = '$prevbal', latechg = '$latechg', hudpay = '$hudpay', paidday = '$paidday' WHERE amtpaid >0"; if(mysqli_query($link, $sql)){ echo ""; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); ?> <!DOCTYPE html><html> <head> <title>record payment</title> <html><head> <script type="text/javascript"> var monthNames = [ "January","February","March","April","May","June","July", "August","September","October","November","December" ]; var today = new Date(); var date = monthNames[today.getMonth()] + " - " + today.getDate() + " - " + today.getFullYear(); </script> </head> <body><center> Date:<script type="text/javascript">document.write(date);</script><p> <img src="apt-pic.jpg" alt="apartment" height=250 width=800><p> For:<SELECT name="options"> <option value="#990033" style="background-color: Violet;">Rent payment</option> <option value="#003300" style="background-color: Aquamarine;">Background Check</option> <option value="#6600cc" style="background-color: Pink;">Security Deposit Payment</option> <option value="#003300" style="background-color: Aquamarine;">Damages Payment</option> <option value="#990033" style="background-color: Violet;">Late Charges Payment</option> <option value="#003300" style="background-color: Aquamarine;">Court Costs Payment</option> <option value="#6600cc" style="background-color: Pink;">NSF Payment</option> <option value="#990033" style="background-color: Violet;"> </option> </SELECT><p> Tenant paying is: <?php echo $_POST["unit"]; ?> - Amount paid is: <?php echo $_POST["amtpaid"]; ?> - Balance due is:<?php echo $owed; ?><br> <b><input type="text" size="35" maxlength="35" name=frm.Name" value="sign" STYLE="color: #000000; font-weight: bold; background-color: #ffccff;" onFocus="this.value=''"><br> <h3>We Thank You</h3> </center></body></html> <?PHP?> PHP: ==========================
What are you expecting from this code? $amtpaid = (int)'amtpaid'; $amtdue = (int)'amtdue'; $prevbal = (int)'prevbal'; $latechg = (int)'latechg'; $secdep = (int)'secdep'; PHP: all those variables are going to be 0 the integer value of a string is always zero.
I get "record was updated successfully" but I think my definitions ( lines 28-38 are wrong. -------------------------------- <html> <head> <title>Refresh payment database file</title> </head> <body> <?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "root", "", "homedb"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } //MySqli Select Query $sql = "select * FROM paytbl where amtpaid !=0"; $result = mysqli_query($link,$sql); if (!$result) { printf("Error: %s\n", mysqli_error($link)); exit(); }else{ $results = array(); while($row = mysqli_fetch_array($result)){ $results[] = $row; } $id='id'; $amtpaid = (int)'amtpaid'; // line 28 $amtdue = (int)'amtdue'; $prevbal = (int)'prevbal'; $latechg = (int)'latechg'; $secdep = (int)'secdep'; $damage = (int)'damage'; $courtcost = (int)'courtcost'; $nsf = (int)'nsf'; $hudpay = (int)'hudpay'; $comments = 'comments'; $paidday = 'paidday'; // line 38 // ---------------------------------------- $due = $amtdue + $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf - $hudpay; /* if no pay or part pay, add $35 to latechg field and amount not paid to prevbal field */ if ($amtpaid < $due) { $prevbal = $amtdue - $amtpaid; $latechg = $latechg + 35.00; } /* if over-payment subtract over-payment from prevbal */ if ($amtpaid > $due) { $prevbal = $amtpaid - $amtdue; } // give every effected record the below values $amtpaid = 0; $paidday = ''; $secdep = 0; $damage = 0; $courtcost = 0; $nsf = 0; $hudpay = 0; $comments = ' '; // Perform a query, check for error $sql = "UPDATE paytbl SET amtpaid = '$amtpaid', prevbal = '$prevbal', latechg = '$latechg', secdep = '$secdep', damage = '$damage', courtcost = '$courtcost', nsf = '$nsf', hudpay = '$hudpay', comments = '$comments' WHERE id=$id"; if(mysqli_query($link, $sql)){ echo "record was updated successfully."; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); } ?> </body></html>
I'm trying to update any records that have paid(amtpaid !=0, if that's correct). I'm not sure how to code line 28-38. The if statement at line 45 is intended for records that have paid (amtpaid), as is everything. The duedate is not advanced. I have tried to resolve several of these issues for some time. There is no error. Anyone want to help/advise? the code: <html> <head> <title>Refresh payment database file</title> </head> <body> <?php $link = mysqli_connect("localhost", "root", "", "homedb"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } //MySqli Select Query $sql = "select * FROM paytbl where amtpaid !=0"; $result = mysqli_query($link,$sql); if (!$result) { printf("Error: %s\n", mysqli_error($link)); exit(); }else{ $results = array(); while($row = mysqli_fetch_array($result)){ $results[] = $row; } $id='id'; $amtpaid = (int)'amtpaid'; // line 28 $amtdue = (int)'amtdue'; $prevbal = (int)'prevbal'; $latechg = (int)'latechg'; $secdep = (int)'secdep'; $damage = (int)'damage'; $courtcost = (int)'courtcost'; $nsf = (int)'nsf'; $hudpay = (int)'hudpay'; $comments = 'comments'; $paiddate = 'paiddate'; // line 38 $due= 0; // ---------------------------------------- $due = $amtdue + $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf - $hudpay; /* if no pay or part pay, add $35 to latechg field and amount not paid to prevbal field */ if ($amtpaid < $due) { $prevbal = $amtdue - $amtpaid; $latechg = $latechg + 35.00; // line 45 $amtpaid = 0; $secdep = 0; $damage = 0; $courtcost = 0; $nsf = 0; $hudpay = 0; $comments = ' '; } /* if over-payment subtract over-payment from prevbal */ if ($amtpaid > $due) { $prevbal = $amtpaid - $amtdue; $amtpaid = 0; $secdep = 0; $damage = 0; $courtcost = 0; $nsf = 0; $hudpay = 0; $comments = ' '; } // Perform a query, check for error $sql = "UPDATE paytbl SET amtpaid = '$amtpaid', duedate = DATE_ADD(duedate, INTERVAL 1 MONTH), prevbal = '$prevbal', latechg = '$latechg', secdep = '$secdep', damage = '$damage', courtcost = '$courtcost', nsf = '$nsf', hudpay = '$hudpay', comments = '$comments' WHERE amtpaid !=0"; if(mysqli_query($link, $sql)){ echo "record was updated successfully."; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); } ?> </body></html>
Hello, I've had a similar experience with a PHP update issue on my website. After updating the PHP version, I noticed that some pages were not displaying correctly and returning error messages. I was able to resolve the issue by first checking the error logs to identify the specific issue. In my case, it was a compatibility issue with a PHP extension that was not supported in the new version. Next, I reached out to my web hosting provider and they were able to downgrade my PHP version to the previous one that worked. They also provided recommendations for updating the website's code to ensure compatibility with the new PHP version. Overall, it's important to ensure that all components, including PHP extensions and website code, are compatible with the new PHP version before updating. And if you do encounter issues, don't hesitate to reach out to your web hosting provider or a PHP expert for assistance.
I started this project 1 1/2 years ago with this very forum and after all this time and so much research, I may be further behind now. I appreciate any and all help but most offered assumes prior knowledge. I'm still not sure how to define a variable database field so that it can be added, updated, echoed/printed or if " or ' should be used and don't remember seeing such reference. Thanks again for your input.
amtpaid is a database field that is: decimal 8,2 and may be 0.00 or may be more: I have asked repeatedly for the correct way to code this variable to reflect it's value and been advised: $amtpaid = (double)'amtpaid';, $amtpaid=$row['amtpaid'];, $amtpaid = (int)'amtpaid'; and told to "use different logic, change language, everything except "just do this". duedate is a database field that is: date: $dueday = 'dueday'; works in update.- dueday = DATE_ADD(dueday, INTERVAL 1 MONTH), comments is text and be blank or not: $comments = 'comments'; if not present: undefined - if present: php understands "comments" as it's value. I want to code them so that php understands their values and I can refer to them. Why cannot someone answer this question?