从数据库中检索信息并在php中显示

时间:2013-03-20 01:00:00

标签: sql database return

当用户在搜索页面上并输入说PatientID然后按下搜索按钮时,我希望它转到数据库并根据输入的PatientID提取所有信息。

我试过这个,但没有运气。它正在返回一个空白的白色屏幕。

<?php
    include 'connect.php';

    $id1 = $_POST['PatientID']; //Text box the user searches in
    $result = mysqli_query($con,"SELECT * FROM PatientRecords WHERE PatientID=$id1");

    while($row = mysqli_fetch_array($result))
    {
        echo 
        $row['PatientID'] . " " . 
        $row['FirstName']. " " . 
        $row['LastName']. " " . 
        $row['DOB']. " " . 
        $row['IDNumber1']. " " . 
        $row['Medication1']. " " . 
        $row['Medication1Dosage']. " " . 
        $row['IDNumber2']. " " . 
        $row['Medication2']. " " . 
        $row['Medication2Dosage']. " " . 
        $row['IDNumber3']. " " . 
        $row['Medication3']. " " . 
        $row['Medication3Dosage']. " " . 
        $row['MedicalNotes'];

        echo "<br />";
    }

    mysqli_close($con);
?>

2 个答案:

答案 0 :(得分:1)

SELECT * FROM PatientRecords WHERE PatientID = $id1

答案 1 :(得分:0)

Your query in wrong, In your query you are assigning :id1 to PatientID in where clause
that is nothing beacsue your id1 is store is in $id1 so use that instead of :id1

您的查询

$result = mysqli_query($con,"SELECT * FROM PatientRecords WHERE PatientID=$id1");