1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

redirect to the receipt

Discussion in 'PHP' started by pshaw, May 2, 2021.

  1. #1
    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>
    PHP:

     
    Last edited by a moderator: May 2, 2021
    pshaw, May 2, 2021 IP
  2. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #2
    What are you trying to do? Its not clear at all.

    The code to redirect using PHP is this:

    header("location: your_url_here"); exit;

    You can pass variables to next page like this:
    your_url?var1=value&var2=value2&...

    Replace the "your_url" with an actual URl, then put that in "header" code.

    Like this:
    header("location: https://dptv.in/?v=1&z=2"); exit;

    Use that line wherever you want the redirect to happen.
     
    JEET, May 2, 2021 IP
  3. pshaw

    pshaw Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Thanks for responding. I fill in a form(payments.html) to indicate payment which updates the payment table.
    This is done with "payments.php". I'd like to then redirect to the receipt program(rentreceipt.php) with
    the three variables, "tenant"(who paid), "rentpaid"(how much) and "rentdue"(still owed). I don't understand
    what you're calling "your_url".
     
    pshaw, May 3, 2021 IP
  4. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #4
    JEET, May 3, 2021 IP
    Efetobor Agbontaen likes this.
  5. pshaw

    pshaw Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    this is offline. here are my updated files:
    I should have shown code for the form(following). I have made changes as I understood but payment not made.
    Here are codes, payments.html, payments.php and rentreceipt.php:

    <!DOCTYPE html><html lang="en">
    <head>
    </head>
    <body bgcolor="#ccffff"><center>
    <font size=+2><b> record a payment</font><br>
    <form action="payment.php" method="post">
    <label for="unit">Unit:</label>
    <input type="text" name="unit" id="unit">
    <label for="tenant">Tenant:</label>
    <input type="text" name="tenant" id="tenant">
    <label for="rentpaid">Amt paid:</label>
    <input type="text" name="rentpaid" id="rentpaid">
    <label for="hudpay">Hudpay:</label>
    <input type="text" name="hudpay" id="hudpay"><br>
    <label for="datepaid">Date Paid:</label>
    <input type="text" name="datepaid" id="datepaid">
    <label for="comments">Comments:</label>
    <input type="text" name="comments" id="comments"><br>

    <input type="submit" name="submit" value="make a payment">
    </form></body></html>

    <?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");

    /* --------------------------- below are posted from form ----- */
    $tenant=$_POST['tenant'];
    $unit=$_POST['unit'];
    $rentpaid=$_POST['rentpaid'];
    $hudpay=$_POST['hudpay'];
    $datepaid=$_POST['datepaid'];
    $comments=$_POST['comments'];
    /* --------------------------- above are posted from form ---- */

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

    //$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
    $mysqli->query("Update paytbl SET
    rentpaid = '$rentpaid', datepaid = '$datepaid', paidsum = '$paidsum', hudpay = '$hudpay',
    comments = '$comments'
    where unit = '$unit'");
    ?>

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

    <!DOCTYPE html><html>
    <head>
    <title>rent receipt</title>
    </head>
    <body><center>
    <?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 />";

    $tenant='tenant';
    $rentpaid='rentpaid';
    $rentdue='rentdue';
    ?>
    <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="Amount"
    value="$ <?php echo( htmlspecialchars($row['Rentpaid'] ) ); ?>" /></td>
    <td><input type='text' size = 10 STYLE="color: #000000; background-color: D4D4FF;" name="Balance 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>



    (You must log in or sign up to reply here.)
     
    pshaw, May 3, 2021 IP
  6. pshaw

    pshaw Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #6
    Jeet, once again I got ahead of myself. Your suggestion re the direct didn't work but I need to get
    the payment program to work first. It doesn't. As I posted, I pay the rent via a short form, code here:
    <!DOCTYPE html><html lang="en">
    <head>
    </head>
    <body bgcolor="#ccffff"><center>
    <font size=+2><b> record a payment</font><br>
    <form action="payment.php" method="post">
    <label for="unit">Unit:</label>
    <input type="text" name="unit" id="unit">
    <label for="tenant">Tenant:</label>
    <input type="text" name="tenant" id="tenant">

    <label for="rentpaid">Amt paid:</label>
    <input type="text" name="rentpaid" id="rentpaid">

    <label for="hudpay">Hudpay:</label>
    <input type="text" name="hudpay" id="hudpay"><br>
    <label for="datepaid">Date Paid:</label>
    <input type="text" name="datepaid" id="datepaid">

    <label for="comments">Comments:</label>
    <input type="text" name="comments" id="comments"><br>

    <input type="submit" name="submit" value="make a payment">
    </form></body></html>
    -----------------------------------------------
    the payment code is here:
    <?php
    echo "<center>";echo date('m/d/y');echo "</center>";
    $owe="''";

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

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

    /* --------------------------- below are posted from form ----- */
    $tenant=$_POST['tenant'];
    $unit=$_POST['unit'];
    $rentpaid=$_POST['rentpaid'];
    $hudpay=$_POST['hudpay'];
    $datepaid=$_POST['datepaid'];
    $comments=$_POST['comments'];
    /* --------------------------- above are posted from form ---- */

    $prevbal=$row['prevbal'];
    $latechg=$row['latechg'];
    $secdep=$row['secdep'];
    $damage=$row['damage'];
    $courtcost=$row['courtcost'];
    $nsf=$row['nsf'];
    $rent=$row['rent'];
    $paidsum=$row['paidsum'];
    $latechg=$row['latechg'];

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

    <!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
    $mysqli->query("Update paytbl SET
    rentpaid = '$rentpaid', datepaid = '$datepaid', paidsum = '$paidsum', hudpay = '$hudpay',
    comments = '$comments'
    where unit = '$unit'");

    // $url= "https://dptv.in/rentreceipt.php?ten...={$rentpaid}&rentdue={$rentdue}&unit={$unit}";
    // header("location: $url"); exit;
    ?>
    </center></body></html>
    -------------------------------------------------------
    here is the result:
    Once again I got ahead of myself. I pay the rent my use of this form:
    <!DOCTYPE html><html lang="en">
    <head>
    </head>
    <body bgcolor="#ccffff"><center>
    <font size=+2><b> record a payment</font><br>
    <form action="payment.php" method="post">
    <label for="unit">Unit:</label>
    <input type="text" name="unit" id="unit">
    <label for="tenant">Tenant:</label>
    <input type="text" name="tenant" id="tenant">

    <label for="rentpaid">Amt paid:</label>
    <input type="text" name="rentpaid" id="rentpaid">

    <label for="hudpay">Hudpay:</label>
    <input type="text" name="hudpay" id="hudpay"><br>
    <label for="datepaid">Date Paid:</label>
    <input type="text" name="datepaid" id="datepaid">

    <label for="comments">Comments:</label>
    <input type="text" name="comments" id="comments"><br>

    <input type="submit" name="submit" value="make a payment">
    </form></body></html>
    --------------------------------------------------
    This is the code for the payment: please don't hesitate to tell me a better way
    <?php
    echo "<center>";echo date('m/d/y');echo "</center>";
    $owe="''";

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

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

    /* --------------------------- below are posted from form ----- */
    $tenant=$_POST['tenant'];
    $unit=$_POST['unit'];
    $rentpaid=$_POST['rentpaid'];
    $hudpay=$_POST['hudpay'];
    $datepaid=$_POST['datepaid'];
    $comments=$_POST['comments'];
    /* --------------------------- above are posted from form ---- */

    $prevbal=$row['prevbal'];
    $latechg=$row['latechg'];
    $secdep=$row['secdep'];
    $damage=$row['damage'];
    $courtcost=$row['courtcost'];
    $nsf=$row['nsf'];
    $rent=$row['rent'];
    $paidsum=$row['paidsum'];
    $latechg=$row['latechg'];

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

    <!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
    $mysqli->query("Update paytbl SET
    rentpaid = '$rentpaid', datepaid = '$datepaid', paidsum = '$paidsum', hudpay = '$hudpay',
    comments = '$comments'
    where unit = '$unit'");

    // $url= "https://dptv.in/rentreceipt.php?ten...={$rentpaid}&rentdue={$rentdue}&unit={$unit}";
    // header("location: $url"); exit;
    ?>
    </center></body></html>
    --------------------------------------------------
    here is the result:
    05/05/21
    Rent Payment
     
    pshaw, May 4, 2021 IP
  7. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #7
    You cannot echo anything before "header" code.
    Instead of that header code, try this:

    <?php
    $url="https://dptv.in/rentreceipt.php?rentdue={$rentdue}&unit={$unit}";
    echo '<script type="text/javascript">
    window.location="'.$url.'";
    </script>
    ';
    ?>


    Your code has so many other problems. No security checks, no variable cleaning, nothing is there...
    And you are mixing PHP inside HTML, making things even more confusing.
     
    JEET, May 5, 2021 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #8
    Good freaking gravy, when did we land in 1997?

    Seriously, just throw ALL of that away and start over with markup from THIS century.

    And the same can be said for the PHP. STOP slopping variables into your query strings. It's called PREPARE/EXECUTE, use it! Likewise ditch all the garbage "variables for nothing".

    As to the redirect, WHY? Why not just show the result? But if you insist, add this inside the document <head>

    <meta http-equiv="Refresh" content="0; URL=https://dptv.in/rentreceipt.php?rentdue={$rentdue}&unit={$unit}">
    Code (markup):
    Remembering that you should be doing all your logic and processing BEFORE you even THINK about outputting a damned thing, in which case you could probably just use header()

    Though the 20+ year out of date practices in the PHP likely will bite you on that as much as your 25 year out of date markup.
     
    deathshadow, May 6, 2021 IP
    JEET likes this.
  9. pshaw

    pshaw Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #9
    My code is localhost in property/rentreceipt.php. Should the code be:
    URL=https://dptv.in/property/rentreceipt.php?tenant={$tenant}&rentdue={$rentdue}&unit={$unit}">
     
    pshaw, May 6, 2021 IP
  10. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #10
    @pshaw
    Yes, URL should be like that, and replace "dptv.in" with "localhost"
    That dptv.in is an example domain. Use your own domain.
    Also note, on localhost "https" will not work most likely. You will get page not found error or something like that.
    So on localhost, use "http" instead of "https"
    On website use "https"

    I cannot show example code here, cause forum is not allowing me to post a localhost url...
    Will go something like this:

    if( $_SERVER['HTTP_HOST'] == 'localhost' ){
    $url= "http : //localhost/property/rentreciept.php?token={$token}&rentpaid={$rentpaid}";
    }else{
    $url= "https://dptv.in/property/rentreciept.php?token={$token}&rentpaid={$rentpaid}";
    }

    In the first URL, remove the white spaces.
     
    JEET, May 6, 2021 IP