从表单中保存会话变量[关闭]

need help saving the POST method within a session variable from the form I have tried using

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

I need to then echo the variable on the following page

    session_start();
    if (isset($_POST['Submit'])) { 
    echo $_SESSION["fColour"];
    } 

You set it as $_SESSION["favColour"] but echoing as $_SESSION["fColour"]; Name must be same in session variable

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

Your exercise3.php code.

session_start();
if (isset($_POST['Submit'])) { 
    echo $_SESSION["favColour"];  //Get the session value. The variable name should be same as what you have set.
}