Redirect to the receipt file

Hi, a little prob with code. I have a payment program and want to follow with the receipt. The following
code is the receipt.

  1. I’ve tried to redirect to the receipt file after payment. I have yet to achieve that.
  2. I want the receipt# on the receipt. I swear, I’m trying
  3. I need to send 3 variables to the receipt program, you’re probably laughing thinking how simple this is
    I’ve poured thru the manuals & forums and the discussions are far past my little efforts. Pointers, anything?

the code:

<?php
echo "<center>";echo date('m/d/y');echo "<br />";

// Include config file
require_once "getprerentdb.php";

//MySqli Select Query
$results = $mysqli->query("SELECT * FROM numberstbl");
$receiptno = "receiptno";
$sql = " UPDATE numberstbl
     SET $receiptno = $receiptno + 1 where id=$id  ";
echo "receiptno has been updated successfully !";
echo "<center>";echo "Receiptno is $receiptno";echo "<br />"; // doesn't work

$tenant=$_POST['tenant'];
$rentpaid=$_POST['rentpaid'];
$rentdue=$_POST['rentdue'];
    ?>
<!DOCTYPE html><html>
<head>
     <title>rent receipt</title>
</head>
<body><center><font size=+1> 
<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"> 

<TABLE BORDER="0" CELLPADDING="12" CELLSPACING="5" >
   <TD>
<TABLE BORDER="30" CELLPADDING="12" CELLSPACING="5">
<td>
<input type='text' size = 30 STYLE="color: #000000; background-color: #D4AAFF;" name="from" 
value="<?php echo( htmlspecialchars($row['tenant'] ) ); ?>" /></td>
<td><input type='text' size = 10 STYLE="color: #000000; background-color: D4D4FF;" name="amt" 
value="$ <?php echo( htmlspecialchars($row['rentpaid'] ) ); ?>" /></td>
<td><input type='text' size = 10 STYLE="color: #000000; background-color: D4D4FF;" name="due" 
value="$ <?php echo( htmlspecialchars($row['rentdue'] ) ); ?>" /></td>
<tr>
<td><input type="text" size="25" name="sign" value="Sign here" STYLE="color: 
#000000; font-weight: bold; background-color: #ffccff;" onFocus="this.value=''"></td>
<td colspan=2 align="center"><input type="text" size=15 name="thanks" readonly value="We Thank You:" STYLE="color: 
#000000; font-weight: bold; background-color: #ffccff;" onFocus="this.value=''"></td>
</tr></table>

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

05/02/21
receiptno has been updated successfully !
Receiptno is receiptno

the payment (from a form) code:

<?php
echo "<center>";echo date('m/d/y');echo "</center>";
$id="''";

// Include config file
require_once "getprerentdb.php";

//MySqli Select Query
$results = $mysqli->query("SELECT * FROM paytbl");

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

$tenant='tenant';
$unit='unit';
$rentpaid='rentpaid';
$hudpay='hudpay';
$prevbal='prevbal';
$latechg='latechg';
$secdep='secdep';
$damage='damage';
$courtcost='courtcost';
$nsf='nsf';
$paidsum='paidsum';
$datepaid='datepaid';
$late='late';
$comments='comments';

$owe = $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf;
$rentpaid=$owe; $paidsum=$owe;
?>

<!DOCTYPE html><html>
<head>

<STYLE TYPE="text/css">
.blue {background-color: #ccffff;}
.tan {background-color: #FFD4FF;}
h1.centered-cell {text-align: center;font-size: 1.1em;}
</STYLE>

</head>
<body><center><b><font size=+1>Rent Payment</b><p>

<?php
// ---------------------------------------
      while($row = mysqli_fetch_array($results))  {
// ----------------------------------------
   if(!empty($_POST["update"]))
   {
$mysqli->query("Update paytbl SET
 rentpaid = '$rentpaid', datepaid = '$datepaid', paidsum = '$paidsum', hudpay = '$hudpay', 
comments = '$comments' 
where unit = '$unit'");
}
 }
?>
     
</center></body></html>

Umm yeah, lots and lots of issues here. Here are some basic things to know…

  1. First of all, when you write an echo line, it is going to print the text where you have the echo line. Meaning, in your script you are writing lines like “reciptno has been updated successfully” before you even start your DOCTYPE. You can run PHP code before the start of the document (it is quite common) but you should be writing your echos out in the body of the document after the DOCTYPE, head etc have been shown.

  2. For your form elements, they should be inside a form element. Right now I see a bunch of input elements, selects etc, but none of them are contained in a <form> element. Maybe take a look at how forms are put together. That form element is also going to pass those values entered into the form into your receipt page. For a quick tutorial on forms you can check out… https://www.youtube.com/watch?v=fNcJuPIZ2WE (Make sure your method is POST)

  3. In your second example of code, you define a variable like $tenant=$_POST['tenant']; and then like 7 lines down, you redefine that variable instead setting it to 'tenant'. This is wiping out the variables previous value. You should not redefine variables like this.

  4. I see you are querying for all records in paytbl, then looping through them all updating each with the same values in your loop. Did you really want to do this? I don’t think you want to be updating all your records to have the same rentpaid, datepaid, paidsum values, right? You probably want to query for a specific row in the table and update only that row.

  5. A minor thing that should be fixed after everything else is working, but tags like <center> and <font> should not be used anymore. Everything you do with those tags are now done through styling.

Work on these and then see what you get. You can show us your updated code. :slight_smile:

This line

that you comment as “not working”, is working correctly, but perhaps not doing what you want it to do. All that is contained in that variable is the text string “receiptno”, because that’s what you set it to here:

$receiptno = "receiptno";

I suspect what you really wanted to do is to get the receipt number from the query on the line before, in which case it’s more likely that you need to do something like:

$row = $mysqli->fetch_assoc();
$receiptno = $row['receiptno'];

After you’ve executed a SELECT query, you need to fetch the results. As you’ll only have one result here, there’s no need for anything more than that single line, which will retrieve the first row and stick it in the $row array. You can then use it. If you’re retrieving more than one row, then you’ll need to use other techniques.

In your next query:

$sql = " UPDATE numberstbl
     SET $receiptno = $receiptno + 1 where id=$id  ";

I notice that you create the query, but you don’t actually execute it anywhere. So the receipt number hasn’t been updated, but your code displays the “success” message regardless of that. You need to call $mysqli->query() with that query string* and then look at the return to see whether it worked or not, then you can decide whether to display the success message or not.

I see in that query you also use a variable called $id, but I can’t see where that comes from. That may also be causing you a problem.

(* Well, not that query string, because now that you have a value in $receiptno instead of just a string - presuming the suggested code worked, that is - the query won’t be valid. But just drop the $ sign from before receiptno in the query and, presuming that is your column name, that should sort it.)

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