我想將一些使用SESSION的變量從一個PHP頁面傳遞到下一個。將PHP變量從一個動態頁面傳遞到另一個
第一頁包含這些代碼,並在用戶點擊提交後,它進入第2頁:
<!--SESSIONS TO PASS ON VARIABLES-->
<?php $_SESSION['file'] = $file; ?>
<?php $_SESSION['linecount'] = $linecount; ?>
<?php $_SESSION['priceperpost'] = $priceperpost; ?>
<?php $_SESSION['totalcost'] = $totalcost; ?>
<!--//SESSIONS TO PASS ON VARIABLES-->
這是我下一個頁面,第2頁上,提交表單後:
<!--VARIABLES FROM PREVIOUS PAGE-->
<?php $file = $_SESSION['file']; ?>
<?php $linecount = $_SESSION['linecount']; ?>
<?php $priceperpost = $_SESSION['priceperpost']; ?>
<?php $totalcost = $_SESSION['totalcost']; ?>
<!--//VARIABLES FROM PREVIOUS PAGE-->
但它沒有得到,因爲我想呼應第2頁中的變量代碼:
<u>Number of Posts:</u> <?php echo ($linecount); ?><br>
<br>
<u>Price Per Post:</u> $<?php echo ($priceperpost); ?> <br>
<u>Total Cost:</u> $<?php echo ($totalcost); ?><br>
<br>
請幫忙,因爲我不知道我做錯了什麼,任何幫助將不勝感激。
是的,我也呼籲在session_start
下面是更新後的代碼:
<?php
session_start();
$_SESSION['file'] = $file;
$_SESSION['linecount'] = $linecount;
$_SESSION['priceperpost'] = $priceperpost;
$_SESSION['totalcost'] = $totalcost;
?>
和下頁
<?php
session_start();
$file = $_SESSION['file'];
$linecount = $_SESSION['linecount'];
$priceperpost = $_SESSION['priceperpost'];
$totalcost = $_SESSION['totalcost'];
?>
你已經調用在session_start()? – chrisbulmer
如果您在文件頂部調用session_start(),在html之前,您仍然有問題,請告訴我們您是否收到任何錯誤或通知? –
在第一頁上,$ file,$ linecount等的值來自哪裏? –