Hi, the scenario is:
I run an apartment complex, someone comes in to pay their rent. I fill in an html form
to record payment(update "payments" database table) and print a receipt.
I hope u will look at it and offer advice. I hope to combine both
the payment and receipt. I don't understand the "non numeric" error and I'm obviously doing
my echoes wrong as the receipt# is not displayed on the receipt(instead of the value in the
"numberstbl" it displays "receiptno".

the code:

<!DOCTYPE html><html>
<head>
<title>rent payment and receipt</title>
</head>
<body><center>
<?php
echo "<center>";echo date('m/d/y');echo "</center>";
// Include config file
require_once "getpayments.php";

//MySqli Select Query$results = $conn->query("SELECT rentdue FROM payments");

$unit=$_POST['unit']; $rentpaid=$_POST['rentpaid'];
$hudpay=$_POST['hudpay']; $datepaid=$_POST['datepaid'];

$unit='unit'; $rentpaid='rentpaid'; $rentdue='rentdue'; $hudpay='hudpay';
$prevbal='prevbal'; $latechg='latechg'; $datepaid='datepaid'; $prev="0.00"; $late="0.00";

// if no pay or part pay add $10 to latechg and amount not paid to prevbal
if ($rentpaid < $rentdue)
{ $latechg = $latechg + "10.00"; $prevbal = $rentdue - $rentpaid; }
// if payment = rentdue
elseif ($rentpaid == $rentdue)
 { $prevbal = $prev; $latechg = $late; }

// if over-payment subtract over-payment from prevbal
elseif ($rentpaid > $rentdue )
{ 
$prevbal = $rentpaid  - $rentdue; $latechg = $late; } // ***  29 non numeric both *** 

//MySqli Select Query
$results = $conn->query("SELECT receiptno FROM numberstbl");
$receiptno='receiptno';
?>
<b><?php echo $_POST["receiptno"]; ?>
<!--<img src="apt-pic.jpg" alt="apartment" height=250 width=800><br> -->
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><br>

<input type="text" size = 25 STYLE="color: #000000; background-color: #D4AAFF;" name="Name" value="Business Name -">
<input type="text" size = 25 STYLE="color: #000000; background-color: #D4D4FF;" name="Addy1" value="Business address -">
<input type="text" size = 25 STYLE="color: #000000; background-color: #D4AAFF;" name="Addy2" value="City, State, Zip"><br>

<b> unit paying is: <?php echo $_POST["unit"]; ?> -
Amount paid is: <?php echo $_POST["rentpaid"]; ?> -
Amount due is: <?php echo $rentdue; ?></b><br> // *** line 54 ****

<b>Sign here</b><input type="text" size=75 name="sign"><br>
<input type="text" size=25 name="thanks" readonly value="We Thank You:" STYLE="color:
#000000; font-weight: bold; background-color: #ffccff;" onFocus="this.value=''"><br>

<?php
/* Perform a query, check for error */
if(!empty($_POST["update"]))
   {
$sql = "UPDATE payments SET
rentpaid='$rentpaid', hudpay='$hudpay', prevbal='$prevbal', latechg='$latechg', datepaid='$datepaid' 
where unit = '$unit'";
if ($conn->query($sql) === TRUE) { echo "ng"; } 
else { echo "Error updating record: " . $conn->error; }
    }
/* Perform a query, check for error */
if(!empty($_POST["update"]))
   {
$sql = "UPDATE numberstbl SET 
receiptno = $receiptno + 1 where id=1";
if ($conn->query($sql) === TRUE) { echo "ng"; } 
else { echo "Error updating record: " . $conn->error; }
$conn->close();
 }
?>

</center></body></html>

errors:
06/30/21

Warning: A non-numeric value encountered in C:\xampp\htdocs\property\payment.php on line 29

Warning: A non-numeric value encountered in C:\xampp\htdocs\property\payment.php on line 29

Notice: Undefined index: receiptno in C:\xampp\htdocs\property\payment.php on line 37

unit paying is: apt1 - Amount paid is: 530.00 - Amount due is: rentdue
// * line 54 **

On line 29, you have the code

$prevbal = $rentpaid  - $rentdue; $latechg = $late;

So basically you're saying take the value of $rentpaid, subtract $rentdue, and stick the difference into the $prevbal variable.

However, on line 16, you have the code:

$unit='unit'; $rentpaid='rentpaid'; $rentdue='rentdue'; $hudpay='hudpay';

So here we are setting the value of the $rentpaid variable to the string 'rentpaid' and the value of the $rentdue variable to the string 'rentdue'.

So it's complaining because how are you expecting it to set $prevbal equal to the value of $rentpaid minus $rentdue? How do you expect it to do a math equation and calculate the difference of two strings? It's literally complaining that it can't do a math equation with non-numeric values. It needs numbers :)

Then it's complaining about an error on line 37, but I actually think this translates to line 35 in the code above.

<b><?php echo $_POST["receiptno"]; ?>

Here it's saying that you're trying to print the value when a POST is done passing in the receiptno field into the form, but complaining that field is not being passed into the form.

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.