update confirmation

1Tsme1941

Member
I only want to print if unsuccessful?

$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; }
 

Trizoy

VIP Member
I don't php much.. but I think it is == not ===
And then
if ($conn->query($sql) == False) { echo "Error updating record: " . $conn->error; }
 

1Tsme1941

Member
I did as suggested:
"if ($conn->($sql) !== true) echo "Failed to update receiptno"; " but added { and }
I get:
Parse error: syntax error, unexpected '']; ' (T_CONSTANT_ENCAPSED_STRING), expecting ']' on line 62
The only place "]" is used is lines 10-13. Time to replace NEW machine?
-------------------------------------------------------------------------
the code:
<html>
<head>
<title>make payment and print receipt</title>
</head>
<body><center>
<?php
// Include config file
include 'getprerentdb.php';

$unit = $_POST['unit']; // line 10
$amtpaid = $_POST['amtpaid']; // ********************************** is 530.00
$hudpay = $_POST['hudpay'];
$datepaid = $_POST[datepaid'];

$amtdue = 0;
$prevbal=0.;
$latechg=0.;
$secdep=0.;
$damage=0.;
$courtcost=0.;
$nsf=0.;
$paidsum=0.;
$comments="comments";
$receiptno=0;

$sql = "UPDATE numbers SET receiptno = receiptno+1 WHERE id=1";
if ($conn->($sql) !== true) { echo "Failed to update receiptno"; }
else { echo "receiptno updated successfully"; }
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();
?>
<br>
<div class="containerBox">
<img class="img-responsive" src="apt-pic.jpg" height=200 width=500>
<div class='text-box'> // ********************************************* line 62
<p class='dataNumber'><input type="text" size = 65 STYLE="color: #000000;
background-color: #D4AAFF;" value="Company Name"><br>
</div></div>

<STYLE TYPE="text/css">
.containerBox {
position: relative;
display: inline-block;
}

.text-box {
position: absolute;
height: 30%;
text-align: center;
width: 100%;
margin: auto;
top: 0;
bottom: 0;
right: 0;
left: 0;
font-size: 30px;
}

.img-responsive {
display: block;
max-width: 100%;
height: 120px;
margin: auto;
padding: auto;
}

.dataNumber {
margin-top: auto;
}
</STYLE>
<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>

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

Cromewell

Administrator
Staff member
if ($conn->($sql) !== true) { echo "Failed to update receiptno"; }
else { echo "receiptno updated successfully"; }
When I copied your code, to show you how to reverse the test I missed that this was wrong. $conn->query($sql), the query part is missing.

Then, because of the else branch, you should see receiptno updated successfully if the query worked.

With the bug (the way written now) you see it because $conn->($sql) does not return false even though the database is not being updated
 

1Tsme1941

Member
I tried this:
$sql = "UPDATE numbers SET receiptno = receiptno+1 WHERE id=1";
if ($conn->query($sql) !== true) { echo "Failed to update receiptno"; }
else { echo " "; }
echo "receipt # is " .$receiptno . "<br>";
Updates but doesn't display a message.

Now please check out line 116:
Amount due: <?php echo $prevbal; ?><br> // **************** this IS 0.00 but displays 530.00 line 116
 
Top