douzhenchun6782 2013-04-26 04:05
浏览 60
已采纳

错误:注意:未定义的索引

I have a form which gets patient data and sends it to the database; However an error is occurring when the submit button is click;

Notice: Undefined index: $patient_lastname line 14

Can any one tell me why this error is occuring?

insert.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>

insert_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);
 ?>
  • 写回答

2条回答 默认 最新

  • dsgwii4867 2013-04-26 04:09
    关注

    You mistakenly added $ before post values.

    change this

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

    to

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

    See here your post input value name property

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

    Same goes for other as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想用@vueuse 把项目动态改成深色主题,localStorge里面的vueuse-color-scheme一开始就给我改成了dark,不知道什么原因(相关搜索:背景颜色)
  • ¥15 flask实现搜索框访问数据库
  • ¥15 mrk3399刷完安卓11后投屏调试只能显示一个设备
  • ¥20 白日门传奇少一个启动区服和启动服务器的快捷键,东西都是全的 , 他们说套一个出来就行了 但我就是弄不好,谁看看,
  • ¥100 如何用js写一个游戏云存档
  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计