Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将所选选项传递到其他页面_Php_Html - Fatal编程技术网

Php 如何将所选选项传递到其他页面

Php 如何将所选选项传递到其他页面,php,html,Php,Html,当我使用Select标记时,在使用$\u会话变量的第二个页面中没有显示任何无法看到的内容。有人帮我:我很困惑: 我的第一页: <?php session_start(); if(isset($_SESSION['a'])){ echo $_SESSION['a']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w

当我使用Select标记时,在使用$\u会话变量的第二个页面中没有显示任何无法看到的内容。有人帮我:我很困惑: 我的第一页:

  <?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>

无标题文件
12
13
我的第二页:

 <?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>

无标题文件
aaa

在您的
isset($\u post)
中,这应该是
isset($\u post)
您正在发布到
test2.php
,因此只有
test2.php
才会收到
$\u post
,而不是第一页


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

这将起作用:只需将$\u 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>

无标题文件
12
13

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

<?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>

无标题文件
12
13
试试这个

if(isset($_POST) && !empty($_POST)){
 echo 'your selected option : '.$_POST['a'];
}
可能的副本:
<?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>
if(isset($_POST) && !empty($_POST)){
 echo 'your selected option : '.$_POST['a'];
}