我在带有模式页面的第一页上具有搜索框$_POST['search']。在模式页面上,我能够显示该搜索框中的值。但是,当我单击“提交”按钮以在第二页上发布时,搜索框变量返回一个空值。请帮助我。

这是我的html代码

<?php

session_start();

$globalpid = $_POST['search'];

$_SESSION['search'] = "$globalpid";

?>

<?php

require_once 'config.php';
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="Hello World">
<!-- Latest compiled and minified CSS -->
    <link rel="stylesheet"  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/custom.css">
    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
</head>
    <body>

        <div class="contaner">

            <header>

                <?php require_once 'header.php'; ?>

            </header>

                <?php require_once 'menu.php'; ?>
<div class="container">
                    <div class="panel panel-default panel-info">
                        <div class="panel-heading"><h3 class="panel-title">Billing Section</h3></div>
                            <div class="panel-body">
                                <form action="table.php" method="POST"  class="form-inline">
                                    <div class="form-group">
                                            <input type="text" name="search" size="50"  id="element-1" class="form-control" style="margin-top: 5px;" placeholder="Enter Patient ID" /><br />
                                            <input type="submit" name="submit" value="Search" style=" margin-top: 5px; width: 150px;" class="btn btn-info" />
                                    </div>
                                </form>
                            </div>

                            <?php

                                if (empty($_POST['search']))
                                {
                            ?>
                                <div class="panel-footer">
                            <?php       echo "There was no search results!"; } ?>
                                </div>
                    </div>
                </div>

最佳答案

确保您的表单action =“首页的网址”。我认为您没有将$ _POST ['search']分配给$ globalpid。在首页尝试以下代码:

第一页

 <?php
 session_start();
 if(isset($_POST['search'])){
   $globalpid = $_POST['search'];
   $_SESSION['search'] = "$globalpid";
 }
 ?>


第二页

<?php
  session_start();
  //print_r($_SESSION);
  if(isset($_SESSION['search'])){
      $globalpid = $_SESSION['search'];
      echo $globalpid;
  }


?>

10-05 20:28