-2

当我使用 Select Tag 时,没有显示任何内容,因为使用 $_SESSION 变量在第二页中看不到。有人帮助我:我很困惑:我的第一页:

  <?php
    session_start();
    if(isset($_SESSION['a'])){
        echo $_SESSION['a'];
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <form id="form1" name="form1" method="post" action="test2.php">
      <label for="df"></label>
      <input type="text" name="df" id="df" />
      <select name="a">
      <option value="12" />12

      <option value="13"/>13

      </select>
      <input type="submit" value="send" />
    </form>
    <?php
    if(isset($_post)){
        if(isset($_POST['a'])){
    $_SESSION['a']= $_POST['a'];
    }
    }
    ?>
    </body>
    </html>

我的第二页:

 <?php
    session_start();
    $r12=13;
    if(isset($_SESSION['a'])){
        echo $r12;
    }

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>

    aaa
    <?php

    if(isset($_SESSION['a'])){
        echo $_SESSION['a'];
    }
    ?>
    </body>
    </html>
4

6 回答 6

1
<input type="submit" value="send" name="submit"/>

    if(isset($_POST['submit'])){
于 2013-05-27T11:43:34.930 回答
0

这将起作用:只需将 $_POST['a'] 设置为会话,您也可以在其他页面上使用它。

<?php
    session_start();
    if(isset($_POST['submit'])){
        echo $_POST['a'];
        }
    else{
    ?>
<head>
    <title>Untitled Document</title>
</head>
<body>
    <form name="form1" method="post" action="index.php">
    <input type="text" name="df" id="df" />
        <select name="a">
            <option value="12" >12</option>
            <option value="13">13</option>
        </select>
    <input type="submit" value="send" name='submit' />
    </form>
    <?php
    }
    ?>
</body>
</html>
于 2013-05-27T11:57:57.703 回答
0

您正在发布到test2.php,所以只会test2.php收到$_POST,而不是第一页!

如果您var_dump($_POST)第二页上调用,您应该会看到正在发送的变量。但是$_POST当表单显示在第一页时(即在表单提交之前)将为空。

于 2013-05-27T11:44:44.880 回答
0

在你的isset($_post),这应该是isset($_POST)

于 2013-05-27T11:40:57.827 回答
0

这是另一种方式,您的第一页应该是这样的..

<?php
session_start();

if(isset($_SESSION['a'])){
   echo $_SESSION['a'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Untitled Document</title>
 </head>
 <body>
   <form id="form1" name="form1" method="post">
      <label for="df"></label>
        <input type="text" name="df" id="df" />
      <select name="a">
         <option value="12" />12
         <option value="13"/>13
        </select>
      <input type="submit" value="send" name="submit"/>
   </form>
<?php
if(isset($_POST['submit'])){
   if(isset($_POST['a'])){
      $_SESSION['a']= $_POST['a'];
        $url = 'test2.php'; // Define the URL:      
        header("Location: $url");
        exit(); // Quit the script.         
    }
}
?>
 </body>
</html>
于 2013-05-27T12:04:48.023 回答
-1

尝试这个

if(isset($_POST) && !empty($_POST)){
 echo 'your selected option : '.$_POST['a'];
}
于 2013-05-27T12:11:06.077 回答