0

I have three pages start.html page2.php and final.php

start.html takes some form data variables (firstname,lastname,city,state) and sends it to page2.php using POST forms.

I then want to send those post variables on to final.php using different methods. firstname and lastname as query string (GET variables) and city and state as hidden variables to be passed via POST to page3.

I understand how to do each separately but is it possible to do both at a time?

what I have tried, which is a best guest, on page2.php:

<?php

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$city = $_POST['city'];
$state = $_POST['state'];

$url = "final.php?firstname=".$firstname."&lastname=".$lastname;


<form action="<?php echo $url; ?>" method="post">
    <input type="hidden" name ="city" value="<?php echo $city; ?>">
    <input type="hidden" name ="state" value="<?php echo $state; ?>">
    <input type="submit" value="next page">
</form>


?>

or a header(location: $url);

maybe use href?

user47835
  • 159
  • 2
  • 13
  • You can only do a `POST` or a `GET` separately and only one at a time. Why do you need to send some as a `GET` and some as a `POST`? – Blinkydamo Nov 17 '16 at 07:54
  • Possible duplicate, please check this: http://stackoverflow.com/questions/2749406/post-and-get-at-the-same-time-in-php – Pixel1002 Nov 17 '16 at 07:56
  • Does the code above not do what you want? The $_GET array should be populated with first/last name in `final.php` and the $_POST array also with city & state bby the looks of this...?? – Professor Abronsius Nov 17 '16 at 08:00
  • blinkydamo this is a demo/test normally i would probably agree with you – user47835 Nov 17 '16 at 08:20
  • for some reason this started working, i was getting an error before but this code should work now – user47835 Nov 17 '16 at 08:34

2 Answers2

1

You can use session to do that, As your question I passed firstname and lastname using get and use sessions to pass other values.

page2.php

<?php
session_start();

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$city = $_POST['city'];
$state = $_POST['state'];

$_SESSION['city'] = $city;
$_SESSION['state'] = $state;

$url = "final.php?firstname=".$firstname."&lastname=".$lastname;

?>

<a href="<?php echo $url; ?>">next page</a>

final.php

<?php
session_start();

echo $_GET['firstname'];
echo $_GET['lastname'];

echo $_SESSION['city'];
echo $_SESSION['state'];

?>
Gayan
  • 2,845
  • 7
  • 33
  • 60
0
<?php

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$city = $_POST['city'];
$state = $_POST['state'];

    $url = "final.php?firstname=".$firstname."&lastname=".$lastname;
    ?>

    <form action="final.php" method="post">
        <input type="hidden" name ="city" value="<?php echo $city; ?>">
        <input type="hidden" name ="state" value="<?php echo $state; ?>">
        <a href="<?php echo $url; ?>">next page</a>
    </form>

use the form to POST the city and state to final.php and the link to GET the firstname and lastname.

FYI: you can follow @user3099298 code to make it simpler.

FullStack
  • 198
  • 7
  • 16