1

I have a page. The user submits the page and sends it to a PHP results page. It works fine. Now, I want the results page to link to another page, and for the elements on that page to depend on what was on the results page. I know how to pass form variables to another page, but I don't know anything about passing non-form variables.

From my searching on the web, my best guess is that I should be passing by URL. Is this correct? If so, a possible problem: the page I want the results page to pass to will have a form, and the user will go to yet another results page by clicking submit (the form data will be sent by POST). Can I send the non-form data (the old results page variable) along with the form data, if the user is going to the other page using POST?

user460847
  • 1,578
  • 6
  • 25
  • 43
  • possible duplicate of [PHP Pass variable to next page](http://stackoverflow.com/questions/871858/php-pass-variable-to-next-page) – outis Dec 28 '11 at 11:26

6 Answers6

2

I strongly suggest using sessions. It's not that hard to learn, php makes it VERY easy using http://php.net/session_start and the $_SESSION variable. Advantage is that you will not have to submit a form on every click, and no information will be displayed in plain text in the URL.

Mikhail
  • 8,692
  • 8
  • 56
  • 82
1

If you are going to use POST to go to the next page the most simple option is to include the data you want to send along using an input type="hidden" element in your form.

Simon Groenewolt
  • 10,607
  • 1
  • 36
  • 64
1

There are several options. However, the easiest may be to simply pass the data on using hidden input fields.

Other options would be using the session, storing to a database between forms, or some combination therein.

Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
1

You might consider using a session to pass the data along.

Paul Sonier
  • 38,903
  • 3
  • 77
  • 117
0

You can embed the non-form data into the second form as hidden fields. To make sure that it is also passed in the link, you can just add it to the URL as a query string, like:

http://..../blah.php?var1=val1&var2=val2

as long as the data you're passing can fit into a URL. Be sure to urlencode() anything you're appending to the URL.

jmans
  • 5,648
  • 4
  • 27
  • 32
0
<?php

start_session();

$_SESSION['Foo'] = 'Bar' // Add stuff here.

?>
Mark Tomlin
  • 8,593
  • 11
  • 57
  • 72