我正在尝试使用 SESSION 将一些变量从一个 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'];
?>