我收到以下代码错误。我有两个 php 文件。一种是从文本字段中获取输入的表单,我希望将其传递给下一个文件。这是我到目前为止所拥有的:
<?php
if(isset($_GET['submit']))
{
$_SESSION['search'] = $_GET['patient_id'];
header('Location:./reception_view_results.php');
}
else{
?>
<!DOCTYPE html>
<html>
<head>
<title>TEST</title>
</head>
<body>
<fieldset>
<legend>Search Appointment</legend>
<form method="GET">
<label>Patient ID</label>
<input type="text" name="patient_id"/>
<input type="submit" name="submit" value="Search"/>
</form>
</fieldset>
</body>
</html>
<?php
}
?>
以及该值将传递到的后续页面:
<!DOCTYPE html>
<html>
<head>
<title>View Results</title>
</head>
<body>
<?php
session_start();
include("connect.php");
$search = $_SESSION['search'];
if ($result = $db->query("SELECT nextapptdate, nextappttime, doc_id pt_id, pt_fname, pt_lname, ph_no
FROM patient
WHERE pt_id = $search
ORDER BY pt_id;"))
{
// display records if there are records to display
if ($result->num_rows > 0)
{?>
<fieldset>
<legend><strong>Search Results</strong></legend>
<table>
<thead>
<tr>
<th>Patient ID
<th>First Name
<th>Last Name
<th>Date of Birth
<th>Doc ID
<th>Phone No.
<th>Next. Appt.
<th>Time
</thead>
<tbody>
<?php
while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->pt_id;
echo "<td>" . $row->pt_fname;
echo "<td>" . $row->pt_lname;
echo "<td>" . $row->ptdob;
echo "<td>" . $row->doc_id;
echo "<td>" . $row->ph_no;
echo "<td>" . $row->nextapptdate;
echo "<td>" . $row->nextappttime;
}?>
</tbody>
</table>
</fieldset>
<?php
}
else{echo "No results to display!";}
}
?>
</body>
</html>
我尝试了几件事:
1)从POST更改为GET。
2)从表单中完全删除动作属性。
3)尝试直接使用会话变量。
我不断在这一行收到错误:
if ($result = $db->query("SELECT nextapptdate, nextappttime, doc_id pt_id, pt_fname, pt_lname, ph_no
FROM patient
WHERE pt_id = $search
ORDER BY pt_id;"))
{
这是因为它不理解$search。
感谢所有的帮助。