PHP : Post get method, need some advice

Solution:
You can use something like this:
1st page (page1.php)
<form action="page2.php" method="post">
<input type="text" name="firstname" value="" />
<input type="text" name="lastname" value="" />
<input type="submit" value="Submit" />
</form>
2nd (page2.php)
Retrieve and validate$_POST['firstname']
and$_POST['lastname']
, then create an output with your required data, you can use hidden fields or create links, according your needs. For instance:
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
// Output with links can pass data by GET method
echo '<a href="page3.php?firstname='.$firstname.'&lastname='.$lastname.'"></a>';
// Output with hidden fields, you can use POST or GET method or even Javascript/Ajax
echo '
<form action="page3.php" method="get">
<input type="hidden" name="firstname" value="'.$firstname.'" />
<input type="hidden" name="lastname" value="'.$lastname.'" />
<input type="submit" value="Submit" />
</form>';
3rd page (page3.php)
If you use the solution with a link or with a form with GET method, you can retrieve the data inpage3.php
just doing the following:
$firstname = $_GET['firstname'];
$lastname = $_GET['lastname'];
Hope it can help you!
Answer
Solution:
Use PHP sessions to store the data between PHP pages. Alternatively, you can just pull the data you already added to your database.
Answer
Solution:
One way that I can think of would be to put the values from the first page into a hidden field on the second page that would be submitted with the form on the second page:
<form action="page3.php" method="post">
<input type="hidden" name="firstname" value="<?php echo $_POST['firstname']; ?>" />
<input type="hidden" name="lastname" value="<?php echo $_POST['lastname']; ?>" />
<input type="submit" value="Submit" />
</form>
Of course you want to make sure that you validate and sanitize your inputs, etc. if any of this is going into a database or could otherwise affect the security and durability of your site.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: using $this when not in object context
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.