5 Replies - 1985 Views - Last Post: 26 February 2013 - 03:57 PM Rate Topic: -----

#1 bateman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 01-February 13

Pass data between web pages using PHP

Posted 26 February 2013 - 12:12 PM

Hello, im kind of new to PHP so this is most likely a relatively easy fix but i do not know how to do it. I have a customer number that is entered in buyer page (p1) and then sent to a confirmation page (p2) then finally the number is written to a data file (p3). I have managed to pass the information from p1 to p2 however i cannot get it to p3. This is the code i am using at the moment. Any help would be great thanks!

Page 1 WORKS
<form action="page2.php" method="post">

    <p> Please enter your customer number: 
    <input type="text" number="cust_num"> </p>


Page 2 WORKS
<form action="page3.php" method="post">
$cust_num=$_POST['cust_num'];
echo "Your order customer: $cust_num ?";


Page 3 DOES NOT WORK
 $cust_num=$_POST['cust_num'];
echo "Your order was successful: $cust_num";


The customer number does not get passed to page 3

Is This A Good Question/Topic? 0
  • +

Replies To: Pass data between web pages using PHP

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,606
  • Joined: 23-August 08

Re: Pass data between web pages using PHP

Posted 26 February 2013 - 12:30 PM

In page 2, add a hidden input element to the form containing the value posted. This will then be posted to page 3.

<input type="hidden" name="cust_num" value="<?= $_POST['cust_num'] ?>" />

Was This Post Helpful? 2
  • +
  • -

#3 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3729
  • View blog
  • Posts: 13,021
  • Joined: 12-December 12

Re: Pass data between web pages using PHP

Posted 26 February 2013 - 12:50 PM

If you are just passing this single value between pages then you can add it as a (GET) query-string to the link to the next page:

<a href="page3.php?cust_num=<?php echo $_POST['cust_num']; ?>">Page 3</a>

without having to construct, and submit, a form on each page. But if your pages already have a form that is submitted (in order to move forward to the next page) then, yes, as JackOfAllTrades 's suggests, just add it as a hidden input.
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Pass data between web pages using PHP

Posted 26 February 2013 - 12:55 PM

The alternative to that would be to save the values from the first form on the server somewhere, like in a Session or in a database. That way the same data would not have to be re-transmitted back and forth between the server and client.

If you don't know how to use Sessions in PHP yet, I'd suggest looking into that. That would, in my opinion, be the better option for this specific scenario.
Was This Post Helpful? 1
  • +
  • -

#5 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3729
  • View blog
  • Posts: 13,021
  • Joined: 12-December 12

Re: Pass data between web pages using PHP

Posted 26 February 2013 - 01:11 PM

View PostAtli, on 26 February 2013 - 12:55 PM, said:

The alternative to that would be to save the values from the first form on the server somewhere, like in a Session or in a database. That way the same data would not have to be re-transmitted back and forth between the server and client.

If you don't know how to use Sessions in PHP yet, I'd suggest looking into that. That would, in my opinion, be the better option for this specific scenario.

Yes, (on a second look at the question) this is actually what I do with something like a customer-number (and I re-validate it on each page). The only thing I pass in the URL are things like a page number (for pagination) or sort order.
Was This Post Helpful? 0
  • +
  • -

#6 bateman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 01-February 13

Re: Pass data between web pages using PHP

Posted 26 February 2013 - 03:57 PM

View PostJackOfAllTrades, on 26 February 2013 - 12:30 PM, said:

In page 2, add a hidden input element to the form containing the value posted. This will then be posted to page 3.

<input type="hidden" name="cust_num" value="<?= $_POST['cust_num'] ?>" />



Thanks a lot - this fixed it straight away!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1