亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP會話未顯示值

PHP會話未顯示值

PHP
大話西游666 2022-10-22 15:57:18
<?php    session_start();?><html>    <head>        <link href="style.css" rel="stylesheet" type="text/css">    </head>    <body>        <div class="pageContainer">            <form action="second.php" class="formLayout" method="post">                <div class="formGroup">                    <label>Name:</label>                    <input type="text" name="first_name"><br>                    <input type="hidden" name="postback" value="true"><br>                </div>                <div class="formGroup">                    <label> Car model:</label>                    <div class="formElements">                        <input type="radio" name="model" value="Mustang">Ford Mustang<br>                        <input type="radio" name="model" value="Subaru">Subaru WRX STI<br>                        <input type="radio" name="model" value="Corvette">Corvette<br>                    </div>                    <input type="submit" name="submit">            </form>            <?php                if (isset($_POST['submit'])) {                    $_SESSION["first_name"] = $_POST["first_name"];                    $_SESSION["model"] = $_POST["model"];                }            ?>        </div>    </body></html>我設置我的代碼以將“first_name”和“model”名稱的值設置到我的會話變量中。當我嘗試訪問表單提交頁面中存儲變量的值時:<?php    session_start();?><html>    <body>        <?php            echo $_SESSION["first_name"];            echo $_SESSION["model"];        ?>    </body></html>我只收到模型值之外的值,而不是 first_name 值。我不明白我在這里做錯了什么。
查看完整描述

1 回答

?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

假設您的第一個文件名為first.php. 如您所示<form>,第二個是second.php.

似乎您正在將數據寫入first.php文件中的會話,但是此代碼將永遠不會運行,因為您將表單提交給second.php而不是first.php!

因此,請移動寫入會話變量的代碼second.php。要測試它是否真的有效,您可以創建一個third.php來顯示它們。

(我不知道為什么要看到這個model集合,但我猜你之前的測試中它仍然存在。)


查看完整回答
反對 回復 2022-10-22
  • 1 回答
  • 0 關注
  • 94 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號