需要帮助在我尝试使用
的表单中保存会话变量中的POST方法 <?php
session_start();
$favcolour = $_POST["favColour"];
$_SESSION["favColour"] = $favcolour;
?>
<form action="exercise3.php" method="POST">
<label for="fColour">Favourite Colour: </label><input type="text"
name="fColour" id="fcolour">
<input type="submit" name="submit" value="Submit">
</form>
然后我需要在下一页回显变量
session_start();
if (isset($_POST['Submit'])) {
echo $_SESSION["fColour"];
}
答案 0 :(得分:1)
您将其设置为
$_SESSION["favColour"]
,但回复为$_SESSION["fColour"]
;
会话变量
答案 1 :(得分:0)
<?php
session_start();
$favcolour = $_POST["favColour"];
$_SESSION["favColour"] = $favcolour; //You have set your session in favColour variable
?>
<form action="exercise3.php" method="POST">
<label for="fColour">Favourite Colour: </label><input type="text"
name="fColour" id="fcolour">
<input type="submit" name="submit" value="Submit">
</form>
session_start();
if (isset($_POST['Submit'])) {
echo $_SESSION["favColour"]; //Get the session value. The variable name should be same as what you have set.
}