0

我有一个表格可以获取患者数据并将其发送到数据库;但是,单击提交按钮时会发生错误;

Notice: Undefined index: $patient_lastname line 14

谁能告诉我为什么会发生这个错误?

插入.php

<!doctype html>
<html lang="en">
<head>
    <title>Form Input Data</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
    <form method="post" action="insert_ac.php">
    <br />
    <table border="1" bgcolor="lightblue">
        <tr>
            <th>
                Nurse Information
            </th>
        </tr>
        <tr>
            <td>
                <label style="color: Red">
                    Please select your name</label>
            </td>
        </tr>
        <tr>
            <td>
                Fullname
            </td>
            <td>
                <select name="valuelist">
                    <option value="valuelist" name="nurse_name" value='<?php echo $nurse_name; ?>'></option>
                    <?php
                        $value=$_POST ["valuelist"];
                        $con = mysql_connect("localhost","root","") or die('Could not connect:'.mysql_error());
                        mysql_select_db("a&e", $con) or die('Could not select database.');

                        $fetch_nurse_name = mysql_query("SELECT DISTINCT Fullname FROM nurse");

                        while($throw_nurse_name = mysql_fetch_array($fetch_nurse_name)) {
                            echo '<option   value=\"'.$throw_nurse_name[0].'">'.$throw_nurse_name[0].'</option>';
                        }
                        echo "</select>";
                    ?>
            </td>
        </tr>
        <tr>
            <td>
                <label style="color: Red">
                    Register Patient</label>
            </td>
        </tr>
        <tr>
            <th>
                Patient Information
            </th>
        </tr>
        <tr>
            <td>
                Forename
            </td>
            <td>
                <input type="text" name="patient_name" size="30" required="true" />
            </td>
        </tr>
        <tr>
            <td>
                Surname
            </td>
            <td>
                <input type="text" name="patient_lastname" size="30" required="true" />
            </td>
        </tr>
        <tr>
            <td>
                Gender
            </td>
            <td>
                <select name="gender">
                    <option value="M">Male</option>
                    <option value="F">Female</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                Date_Of_Birth
            </td>
            <td>
                <select name="dateOfBirth">
                    <option value="">---select date---</option>
                    <?php for ($i = 1; $i <= 31; $i++) : ?>
                    <option value="<?php echo ($i < 10) ? '0'.$i : $i; ?>"><?php echo $i; ?></option>
                    <?php endfor; ?>
                </select>
                <select name="monthOfBirth">
                    <option value="">---select month---</option>
                    <?php for ($i = 1; $i <= 12; $i++) : ?>
                    <option value="<?php echo ($i < 10) ? '0'.$i : $i; ?>"><?php echo $i; ?></option>
                    <?php endfor; ?>
                </select>
                <select name="yearOfBirth">
                    <option value="">---Select year---</option>
                    <?php for ($i = 1945; $i < date('Y'); $i++) : ?>
                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
                    <?php endfor; ?>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                Address
            </td>
            <td>
                <input type="text" name="address" size="54" required="true" />
            </td>
        </tr>
        <tr>
            <td>
                Patient_History
            </td>
            <td>
                <textarea rows="5" cols="20" name="history" wrap="physical">Enter patient's history</textarea>:<br />
            </td>
        </tr>
        <tr>
            <td>
                Illness
            </td>
            <td>
                <select name="illness">
                    <option value="Life Threatening">Critical</option>
                    <option value="Immediate">Immediate</option>
                    <option value="Urgent">Urgent</option>
                    <option value="semi-urgent">Semi-Urgent</option>
                    <option value="non-urgent">Non-urgent</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                Priority
            </td>
            <td>
                <select name="priority">
                    <option value="high">High Priority</option>
                    <option value="moderate">Moderate Priority</option>
                    <option value="low">Low Priority</option>
                </select>
            </td>
            <br />
        </tr>
        <tr>
            <th>
                Assessment
            </th>
        </tr>
        <tr>
            <td>
                Symptoms
            </td>
            <td>
                <input type="text" name="symptoms" size="30" required="true"/>
            </td>
        </tr>
        <tr>
            <td>
                Diagnosis
            </td>
            <td>
                <input type="text" name="diagnosis" size="30" required="true"/>
            </td>
        </tr>
        <tr>
            <td>
                Treatment
            </td>
            <td>
                <input type="text" name="treatment" size="30" required="true"/>
            </td>
        </tr>
        <tr>
            <td>
                <label style="color: Red">
                    Please assign a doctor</label>
            </td>
        </tr>
        <tr>
            <td>
                Doctor
            </td>
            <td>
                <select name="valuelist">
                    <option value="valuelist" name="doc_name" value='<?php echo $doc_name; ?>'></option>
                    <?php
                    $value=$_POST ["valuelist"];
                    $con = mysql_connect("localhost","root","") or die('Could not connect:'.mysql_error());
                    mysql_select_db("a&e", $con) or die('Could not select database.');

                    $fetch_doc_name = mysql_query("SELECT DISTINCT Name FROM doctor");

                    while($throw_doc_name = mysql_fetch_array($fetch_doc_name)) {
                    echo '<option   value=\"'.$throw_doc_name[0].'">'.$throw_doc_name[0].'</option>';
                    }
                    echo "</select>";

                    ?>
            </td>
        </tr>
        <tr>
            <td align="right">
                <input type="submit" name="submit" value="submit" required="true"/>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

插入ac.php

<?php
$con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error());
mysql_select_db("a&e", $con) or die('Could not select database.');



//get Disease values from form
$symptoms = mysql_real_escape_string($_POST['symptoms']);
$diagnosis = mysql_real_escape_string($_POST['diagnosis']);
$treatment = mysql_real_escape_string($_POST['treatment']);

//Assigning value to variable for Patient 
$patient_name = ($_POST['patient_name']);
$patient_lastname = ($_POST['$patient_lastname']);
$gender = ($_POST['$gender']);
$dateOfBirth = ($_POST['$dateOfBirth']);
$monthOfBirth = ($_POST['$monthOfBirth']);
$yearOfBirth = ($_POST['$yearOfBirth']);
$address = ($_POST['address']); 
$history = ($_POST['history']); 
$illness = ($_POST['illness']); 
$priority = ($_POST['priority']); 

// Validate date of birth 
$date = $dateOfBirth.'-'.$monthOfBirth.'-'.$yearOfBirth;

//Validate 


$sql ="INSERT INTO Disease(Illness, Symptoms, Diagnosis, Treatment)
   VALUES('$illness', '$symptoms', '$diagnosis', '$treatment')";
mysql_query($sql,$con) or die('Error: ' . mysql_error());

$sql ="INSERT INTO Priority(Priority)
   VALUES('$priority')";
mysql_query($sql,$con) or die('Error: ' . mysql_error());

$sql="INSERT INTO Patient(Forename, Surname, Gender, Date_Of_Birth, Address, Patient_History, Illness, Priority, Arrival_Time)
VALUES('$patient_name', '$patient_lastname', '$gender', '$date', '$address', '$history', '$illness', '$priority', NOW())";
mysql_query($sql,$con) or die('Error: ' . mysql_error());

echo "1 record added";
 // close connection 
 mysql_close($con);
 ?>
4

2 回答 2

2

$您在发布值之前错误地添加了。

改变这个

$patient_lastname = ($_POST['$patient_lastname']);
$gender = ($_POST['$gender']);
$dateOfBirth = ($_POST['$dateOfBirth']);
$monthOfBirth = ($_POST['$monthOfBirth']);
$yearOfBirth = ($_POST['$yearOfBirth']);

$patient_lastname = ($_POST['patient_lastname']);
$gender = ($_POST['gender']);
$dateOfBirth = ($_POST['dateOfBirth']);
$monthOfBirth = ($_POST['monthOfBirth']);
$yearOfBirth = ($_POST['yearOfBirth']);

在此处查看您的帖子输入值名称属性

<input type="text" name="patient_lastname" size="30" required="true" />

其他也一样。

于 2013-04-26T04:09:05.187 回答
0

您的错误是自我定义的..它表示您尝试从中获取值的数组中没有这样的键

删除 $_POST 中值前面的“$”

代替

$patient_lastname = ($_POST['$patient_lastname']);

$patient_lastname = ($_POST['patient_lastname']);

像这样的代码中还有其他一些。

请避免使用 mysql_* 切换到 PDO 或 mysqli_*

于 2013-04-26T04:17:43.063 回答