0

I know this question has come up several times.

I read all of the posts and tried them but couldn't get them to work.

I simply want to pass the session data from page 1 to page 2 for a radio button. It won't work no matter what I've tried.

Page 1

<form action="step-2.php" method="post">
    <div class="row">
        <div class="card-left"><img src="card.png" /><br /><input type="radio" name="card" value="card-one" /></div>
        <div class="card-center"><img src="card.png" /><input type="radio" name="card" value="card-two" /></div>
        <div class="card-right"><img src="card.png" /><input type="radio" name="card" value="card-three" /></div>
        <div class="card-right"><img src="card.png" /><input type="radio" name="card" value="card-four" /></div>
    </div>
    <div class="row">
        <div class="card-left"><img src="card.png" /><br /><input type="radio" name="card" value="card-five" /></div>
        <div class="card-center"><img src="card.png" /><input type="radio" name="card" value="card-six" /></div>
        <div class="card-right"><img src="card.png" /><input type="radio" name="card" value="card-seven" /></div>
        <div class="card-right"><img src="card.png" /><input type="radio" name="card" value="card-eight" /></div>
    </div>
    <div class="row">
        <div class="card-left"><img src="card.png" /><br /><input type="radio" name="card" value="card-nine" /></div>
        <div class="card-center"><img src="card.png" /><input type="radio" name="card" value="card-ten" /></div>
        <div class="card-right"><img src="card.png" /><input type="radio" name="card" value="card-eleven" /></div>
        <div class="card-right"><img src="card.png" /><input type="radio" name="card" value="card-twelve" /></div>
    </div>
    <div id="messages">

    <?php

    if($_SERVER['REQUEST_METHOD'] == 'POST') {
        if(isset($_POST["card"])) {
            session_start();
            $_SESSION["card"] == $_POST["card"];
        }


        if(!isset($_POST["card"])) {
            echo '<span style=\"color: red;\">' . "Please choose a card before proceeding" . '</p>';
        } else {

        }

    } else { }

    ?>
    <input type="submit" name="to-step-2" value="Next" id="submit" /></div>
</form>

Page 2 (won't receive and display the data)

<?php

if(isset($_SESSION["card"])) {
    $card = $_SESSION["card"];
    echo $card;
} else {
    echo "<h2>No Card Selected</h2>";
    echo "You didn't select a card. Please go back and select one <a href=\"index.php \">Here</a>";
}

?>

I'm just trying to test this in this state so that I can make sure that the data is being passed and then I will work with the data, but right now it doesn't look like the data is being passed. It instead triggers the default "You didn't select a card" message that I have set up.

1 Answer 1

4

At the top of page 2, you need to add session_start(); to resume your session.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.