Php(会话)...如何将文本框值放入会话并将其传递给另一个页面?我收到错误

时间:2015-07-18 01:58:41

标签: php

<?php
session_start();
 ?>
 <form action="HardDisk.php" method="post">//form
 <input type="text" name="user" />
 <?php
if(isset($_POST['user']))
 {
 $_SESSION['userGet']=$_POST['user'];
 }
 ?>
 <input type="submit" value="submit" />
 </form>

  2nd page
 <?php
 session_start();
 ?>
 <?php
 if (isset($_SESSION['userGet'])) {
$form_value = $_SESSION['userGet'];
}
echo $form_value ;
?>

............................................... .................................................. .........

2 个答案:

答案 0 :(得分:1)

您已使用文本框名称检查提交按钮名称。

 <form action="HardDisk.php" method="post">//form
 <input type="text" name="user" />
 <input type="submit" value="submit" name="submit" />
 </form>
<?php
session_start();
if(isset($_POST['submit'])&&isset($_POST['user'])) {
    $_SESSION['userGet']=$_POST['user'];
}
?>

在你的第二页

<?php
session_start(); 
if (isset($_SESSION['userGet'])) {
    echo $form_value = $_SESSION['userGet'];
}

答案 1 :(得分:0)

将提交按钮命名为submit,然后使用以下PHP代码:

if(isset($_POST['submit'])){
    if(isset($_POST['user']))
    {
        $_SESSION['userGet']=$_POST['user'];
    }
}