(t_constant_encapsed_string)

Hi itsme again. I have this prob I can’t get past. This is a program to pay a fee and print a receipt.
I enter the unit and payment into a form and get the message:
Parse error: syntax error, unexpected ‘’; ’ (T_CONSTANT_ENCAPSED_STRING) on line 62.
Please advise. Thanks!

type or paste code here<!DOCTYPE html><html>
<body><center>
<img src="apt-pic.jpg" alt="apartment" height=75 width=200><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>

<?php
$link = mysqli_connect("localhost", "root", "", "prerentdb");
// Check connection
if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }

$unit = $_POST['unit'];
$amtpaid = $_POST['amtpaid'];
$hudpay = $_POST['hudpay'];
$prevbal='prevbal';
$latechg='latechg';
$secdep='secdep';
$damage='damage';
$courtcost='courtcost';
$nsf='nsf';
$paidsum='paidsum';
$receiptno='receiptno';
$id='id';
$due=due';

<b> tenant paying is: <?php echo $_POST["unit"]; ?> -
Amount paid is: <?php echo $_POST["amtpaid"]; ?><br>

<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>

<?php
// Attempt select query execution
$result = mysqli_query($link,"SELECT * FROM payfile");
$results= $results->fetch_all(MYSQLI_ASSOC);

$due = $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf;
$due = $due + $amtdue; $amtpaid = $paidsum;

// if no payment or partial payment, add $10 to latechg field
// and amount not paid to prevbal field
if ($amtpaid < $due)
{ $latechg = $latechg + 10; $prevbal = $due - $amtpaid;  }

// if payment = amtdue clear due
if ($amtpaid == $due)
{ $prevbal = $latechg = $secdep = $damage = $courtcost = $nsf = 0; }
// if over-payment subtract over-payment from prevbal field
if ($amtpaid > $due )
{ $prevbal = $due - $amtpaid; $latechg = $secdep = $damage = $courtcost = $nsf = 0; }

// Perform a query, check for error
$sql = "UPDATE payfile SET
amtpaid='$amtpaid', prevbal='$prevbal', latechg='$latechg', secdep='$secdep', damage='$damage',
courtcost='$courtcost', nsf='$nsf', hudpay='$hudpay', datepaid='$datepaid', paidsum='$amtpaid',
comments='$comments'
Where unit = $unit"; // ********* this seems to be the culprit ************

if ($link->query($sql) === TRUE) { echo "Paid"; } 
else { echo "Error updating record: " . $link->error; 
}

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

You didn’t exit out of PHP before going back into HTML several times. You are also missing a quote. These are the most simplest mistakes you would not be having if you used a proper editor or IDE. You are also using deprecated HTML.

You really need to look at Prepared Statements instead of sticking variables directly into queries like that.

You also seem to have an error in this section of your code:

$result = mysqli_query($link,"SELECT * FROM payfile");
$results= $results->fetch_all(MYSQLI_ASSOC);

but as you don’t seem to use that anywhere, it may not matter.

I am surprised you don’t get other errors. For example you assign these values to variables:

$prevbal='prevbal';
$latechg='latechg';
$secdep='secdep';
$damage='damage';
$courtcost='courtcost';
$nsf='nsf';

and then a few lines later, you try to add them together:

$due = $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf;

Of course, you can’t do that because they’re not numbers, unless your initial value assignments would normally have actual numbers in them. You can concatenate the strings together using ., but that doesn’t make a lot of sense.

Perhaps the only reason you’ve stopped getting “Not numeric” errors is because of the parse error.

1 Like

Hi, thanks for helping me. I still must address the “non-numeric” issue and I ask for help again.
Am I not adding the fields correctly? all these are in the database as decimal (8,2). Should they
be otherwise? My first attempt at parameterized statements - not so good. I searched for but didn’t
find definition for “double” or “float”; used “d” for my decimal fields? Help?
My revised code follows:

<!DOCTYPE html><html>
<body><center>
<img src="apt-pic.jpg" alt="apartment" height=75 width=200><br>
<?php
echo date('m/d/y');echo "</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 = 50 STYLE="color: #000000; background-color: #D4AAFF;" name="Name" value="Business Name"><br>
<input type="text" size = 50 STYLE="color: #000000; background-color: #D4D4FF;" name="Addy1" value="Business address"><br> 
<input type="text" size = 50 STYLE="color: #000000; background-color: #D4AAFF;" name="Addy2" value="City, State, Zip"><br> 
 
<?php
$link = mysqli_connect("localhost", "root", "", "prerentdb"); 
// Check connection
if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }

$unit = $_POST['unit'];
$amtpaid = $_POST['amtpaid'];
$amtdue = 'amtdue';  
$datepaid = $_POST['datepaid'];
$hudpay = 'hudpay';
$prevbal='prevbal';
$latechg='latechg';
$secdep='secdep';
$damage='damage';
$courtcost='courtcost';
$nsf='nsf';
$paidsum='paidsum';
$comments='comments';
$receiptno='receiptno';
$id='id';
$due='due';
// Attempt select query execution
$result = mysqli_query($link,"SELECT * FROM payfile");
$row= mysqli_fetch_array($result);
?>
<b> tenant paying is: <?php echo $_POST["unit"]; ?> - 
Amount paid is: <?php echo $_POST["amtpaid"]; ?><br>
<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> 

<?php
$due = $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf; // line 52 
$due = $due + $amtdue; $amtpaid = $paidsum;                        // line 53 
/* if no payment or partial payment, add $10 to latechg field  and amount not paid to prevbal field */
if ($amtpaid < $due)
 { $latechg = $latechg + 10; $prevbal = $due - $amtpaid;  } 
/* if payment = amtdue clear due */
if ($amtpaid == $due)
 { $prevbal = $latechg = $secdep = $damage = $courtcost = $nsf = 0; }
/* if over-payment subtract over-payment from prevbal field */
if ($amtpaid > $due )
{ $prevbal = $due - $amtpaid; $latechg = $secdep = $damage = $courtcost = $nsf = 0; }

// Perform a query, check for error
$sql = "UPDATE payfile SET
amtpaid=?, prevbal=?, latechg=?, secdep=?, damage=?, courtcost=?, 
nsf=?, hudpay=?, datepaid=?, paidsum=?, comments=? Where unit = ?";

//bind parameters for markers, where (s = string, i = integer, d = double,  b = blob)
$results =  $statement->bind_param('ddddddddsdsi', $amtpaid, $prevbal, $latechg, $secdep, $damage, $courtcost, 
$nsf, $hudpay, $datepaid, $paidsum, $comments, $unit);     // line 69

if($results){ print 'Success! record updated'; }
else{ print 'Error : ('. $mysqli->errno .') '. $mysqli->error; }
?>

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

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

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

Notice: Undefined variable: statement in C:\xampp\htdocs\property\payment.php on line 69
Fatal error: Uncaught Error: Call to a member function bind_param() on null :69 
Stack trace: #0 {main} thrown in C:\ line 69


You’re adding them correctly. The problem is in these lines:

$hudpay = 'hudpay';
$prevbal='prevbal';
$latechg='latechg';
$secdep='secdep';
$damage='damage';
$courtcost='courtcost';
$nsf='nsf';
$paidsum='paidsum';

You set all the variables to contain strings. You can’t add a string to a string because, well, what happens in normal maths if you want to add “Bill” to “Dave”? Nothing, because they’re not numbers. Some languages (VB, for example) allow the “+” symbol to be used either to add numbers, or to concatenate strings (I believe it’s known as “Polymorphism”), but PHP does not. So when you try to add one string to another using a mathematical symbol, you’ll get “Not a Number” errors.

I suspect the assignment lines that I quoted above are the issue. What do you think those lines are doing, or more to the point what do you want them to do?

1 Like

You end up on a fanfiction website, usually.

Your middle case can be simplified into the last case;

If $amtpaid = $due, then
{ $prevbal = $due - $amtpaid; $latechg = $secdep = $damage = $courtcost = $nsf = 0; }
will still set $prevbal to 0.

I also somewhat doubt your calculations in the first case, unless all of those costs are repeating costs.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.