-1

Suppose I have three PHP files: 1.php, 2.php, 3.php

1.php sends data with POST method to 2.php. Now I want 2.php to send the same data to 3.php with POST method. I want to link from 2.php to 3.php with a single button.

How can I do that?

DaveRandom
  • 87,921
  • 11
  • 154
  • 174
palatok
  • 1,022
  • 5
  • 20
  • 30

3 Answers3

3

Use anchor tag

<a href="3.php?var=<?php $_POST['var']?>"></a>

OR

use a form with hidden fields :

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

and submit the form

Prasanth Bendra
  • 31,145
  • 9
  • 53
  • 73
2

Here are 4 options on how to do this (first 3 don't require user action, with the 3rd you can auto-submit, but can let the user see it and submit it manually):

  • In 2.php you simply use include '3.php'; - thus having access to $_POST in 3.php
  • Use stream_context_create
  • Use CURL
  • Re-generate a form with a submit button.

 <form action="3.php" method="POST">
 <?php
 foreach ($_POST as $key => $value) {
     echo "<input type='text' name='{$key}' value='{$value}' />"; // if it's an array, you can serialize it
 }
 ?><input type="submit"></form>

You can now show it to the user, or submit it with javascript.

Vlad Preda
  • 9,780
  • 7
  • 36
  • 63
1

You will have read the data in 2.php and create a form with hidden input tags containing that data, which will have 3.php as action source defined.

e.g

<form action="3.php">

   <input type=hidden" name="foo" value="bar">
</form> 

will post { :foo => bar }

to 3.php

Maybe you also just consider using a user session and save the values in it

dre-hh
  • 7,840
  • 2
  • 33
  • 44