0

I have a very simple app, it's only one php page (page A). I would like add one more php page (page B) that receives data from an html form of "page A". I haven't found any tutorials about it. Can you help me?

piddl0r
  • 2,431
  • 2
  • 23
  • 35
antalk77
  • 1
  • 1

3 Answers3

2

GET METHOD

Page A: (eg. index.html)

<form action="welcome.php" method="get">
  Name: <input type="text" name="fname" />
  Age: <input type="text" name="age" />
  <input type="submit" />
</form>

Page B (welcome php)

Welcome <?php echo $_GET["fname"]; ?>.<br />
You are <?php echo $_GET["age"]; ?> years old!

When to use method="get"?

When using method="get" in HTML forms, all variable names and values are displayed in the URL.

Note: This method should not be used when sending passwords or other sensitive information!

However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases.

Note: The get method is not suitable for very large variable values. It should not be used with values exceeding 2000 characters.

POST METHOD

Page A: (eg. index.html)

<form action="welcome.php" method="post">
  Name: <input type="text" name="fname" />
  Age: <input type="text" name="age" />
  <input type="submit" />
</form>

Page B (welcome php)

Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.

When to use method="post"?

Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

However, because the variables are not displayed in the URL, it is not possible to bookmark the page.

The PHP $_REQUEST Function

The PHP built-in $_REQUEST function contains the contents of both $_GET, $_POST, and $_COOKIE.

The $_REQUEST function can be used to collect form data sent with both the GET and POST methods.

Example

Welcome <?php echo $_REQUEST["fname"]; ?>!<br />
You are <?php echo $_REQUEST["age"]; ?> years old.
glarkou
  • 7,023
  • 12
  • 68
  • 118
0

If you are using Form on Page A then you can post the values from that form to another page B.

if you are not using post or get you can still pass values from one page to another by creating session.

Html form can have action set to Page B and $_POST or $_GET can give you data from page A to Page B

Astha
  • 1,728
  • 5
  • 17
  • 36
0

You are best off looking into a few tutorials this is PHP 101.

You can store the data in a session or cookie. You can use a form to POST data to the next page. you can use GET to send data in the uri

Here is a tutorial for POST and GET

Edit : It sounds like you wish to pass the variables with a redirect. You could set the variables in session and retrieve them later or pass the variables in the redirect and fetch them using $_GET. Rather than redirecting to example.php redirect to example.php?var=value.

piddl0r
  • 2,431
  • 2
  • 23
  • 35
  • post and get work as long as I use them in an app that work with public data only. if there is an authentication (redirect?) when values are posted the values do not arrive – antalk77 Sep 08 '11 at 12:24