0

ここで何が間違っているのかわかりませんが、最初の「未設定の場合」の if からドロップダウンで選択した後も、ドロップダウンは新しい if の出力の上に表示されます。

選択が完了すると、「ukset」または「uknotset」に移動し、ドロップダウンが再び表示されないようにする必要があります。

私が間違っていることは何ですか?

<?php
        session_start();

        // if unset
        if(!isset($_SESSION['grant_access'])) {$_SESSION['grant_access'] = 'unset';}
        if($_SESSION['grant_access'] == 'unset') {
            echo '<p>Make your choice</p>';
            echo '<form action="" onchange="this.submit()" method="post">';
            echo '<select name="thecountry">';
                echo '<option>Choose</option>';
                echo '<option value="hello">Hello</option>';
                echo '<option value="goodbye">Goodbye</option>';
                echo '<option value="unsure">Unsure</option>';
            echo '</select>';
            echo '</form>';
            }

        // if UK is set
        if(isset($_POST['thecountry']) && ($_POST['thecountry'] == 'hello')) {$_SESSION['grant_access'] = 'ukset';}
        if($_SESSION['grant_access'] == 'ukset') {
            echo 'welcome';
            }

        // if UK is not set
        if(isset($_POST['thecountry']) && ($_POST['thecountry'] !== 'hello')) {$_SESSION['grant_access'] = 'uknotset';}
        if($_SESSION['grant_access'] == 'uknotset') {
            echo 'access denied';
            }   

?>
4

2 に答える 2