-1

次のコードでエラーが発生します。私は2つのphpファイルを持っています。1つはテキストフィールドから入力を受け取るフォームで、次のファイルに渡してほしいです。これは私がこれまでに持っているものです:

<?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)フォームからaction属性を完全に削除します。
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を理解していないからです。

すべての助けをありがとう。

4

1 に答える 1

1

doc_idの後にカンマがありません。このように動作するはずです(いくつかのフォーマットを含む)

SELECT
  nextapptdate,
  nextappttime,
  doc_id,
  pt_id,
  pt_fname,
  pt_lname,
  ph_no 
FROM
  patient 
WHERE
  pt_id = $search
ORDER BY
  pt_id

そして、最初のファイルを調べます。グローバル配列は、最初のファイルに欠落しているもの$_SESSIONを呼び出すまで存在せずsession_start、トピックにあるエラーを生成します。

于 2013-03-26T16:23:52.753 に答える