2016-11-17 69 views
0
頁面

我有三頁的start.html使page2.php和final.php發送一個隱藏的後變量和查詢字符串得到變量

的start.html需要某種形式的數據變量(名字,姓氏,城市,狀態)並使用POST表單將其發送到page2.php。

然後我想使用不同的方法將這些post變量發送到final.php。 firstname和lastname作爲查詢字符串(GET變量),並將城市和州作爲隱藏變量通過POST傳遞給page3。

我明白如何分別做每一件事,但一次可以做兩件事嗎?

什麼我都試過了,這是一個最好的客人,就使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> 


?> 

或頭(地點:$網址);

也許使用href?

+0

您只能單獨執行一個'POST'或'GET',且每次只執行一個。爲什麼你需要發送一些作爲'GET'和一些作爲'POST'? – Blinkydamo

+0

可能的重複,請檢查此:http://stackoverflow.com/questions/2749406/post-and-get-at-the-same-time-in-php – Pixel1002

+0

上面的代碼沒有做你想要的嗎? $ _GET數組應該在'final.php'中填入第一個/最後一個名字,而$ _POST數組也可以使用city&state bby這個外觀......? – RamRaider

回答

1

您可以使用session做到這一點,你的問題我用get和使用sessions傳遞其它值傳遞firstnamelastname

使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']; 

?> 
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> 

使用表來發表的城市和國家,以final.php和鏈接來獲得名字和姓氏。

供參考:您可以按照@ user3099298代碼使其更簡單。