我在第一页上有搜索框$_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>
答案 0 :(得分:1)
确保您的表单操作=&#34;第一页的网址&#34;。我认为你没有将$ _POST [&#39; search&#39;]分配给$ 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;
}
&GT;