2013-03-26 73 views
-1

我收到以下代碼的錯誤。我有兩個PHP文件。一種是從文本字段獲取輸入的表單,我希望將其傳遞到下一個文件。這是我到目前爲止有:獲取未定義的索引mysql會話

<?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;")) 
      { 

這是因爲它不理解$搜索。

感謝您的幫助。

+1

我會嘗試添加一個[session_write_close](http://php.net/manual/en/function.session-write-close.php)分配值後會話和重定向之前。 – ficuscr 2013-03-26 16:24:10

+0

JazakAllah khayr的意見。 – 2013-03-26 16:48:07

回答

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這是在第一個文件丟失,會產生你有錯誤在你的主題。

+0

JazakAllah khayr!我已經厭倦了大約2天了。讓我的夜晚。 – 2013-03-26 16:46:23