php变量echo用正确的值插入db错误

时间:2017-04-23 17:10:32

标签: php mysql forms

我有一个带有变量$mrn的php形式的变量。当我通过$_POST[];方法提交数据时,会调用php脚本来提取另一个页面并回显表单中输入的内容并将其提交到db表。当我检查db表时,输入到表单并成功回显的值不是插入到db中的值。表单中的所有其他数据都正确且成功地发布。这个相同的变量没有正确地发布到任何表单上的数据库。我正在查看这篇文章similar issue,因为它是相关的。我不熟悉这些功能,正在读它。

这是我的insert_records php

    <?php
    $page_title = 'Insert Outcomes Data';
    include('php_includes/header.html');

    // Connect to the database
    include_once("php_includes/db_connect.php");

    // Gather the posted data into local variables
    $mrn = $_POST['mrn'];
    $add_hosp_dispo = $_POST['add_hosp_dispo'];
    $date_alt_lvl_cr_sts = $_POST['date_alt_lvl_cr_sts'];
    $actual_discharge_time = $_POST['actual_discharge_time'];
    $actual_discharge_date = $_POST['actual_discharge_date'];
    $gcs_outcome = $_POST['gcs_outcome'];

    // Get user IP Address
    $ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR'));

    // Form data error handling
    if($mrn == ""){
        echo "The form submission is missing data.";   
    } else {
        // End form data error handling
        $sql = "INSERT INTO nys_outcome_info (
            mrn, 
            final_hosp_dispo,
            date_alt_lvl_care,
            actual_discharge_time,
            actual_discharge_date,
            gcs,
            ip_address, 
            record_insert_dtime
        )
        VALUES(
            '$mrn', '$add_hosp_dispo', '$date_alt_lvl_cr_sts', '$actual_discharge_time', 
            '$actual_discharge_date', $gcs_outcome,
            '$ip', now()
        )";
    }

    if (mysqli_query($db_connect, $sql)) { 
      echo "<h3>Demographics have been inserted successfully, you will be auto-directed to the  form.<br /><br /></h3>";
      echo "MRN: $mrn <br />";
      echo "Date of Alternate Level of Care Status: $date_alt_lvl_cr_sts <br />";
      echo "Actual Discharge Time: $actual_discharge_time <br />";
      echo "Actual Discharge Date: $actual_discharge_date <br />";
      echo "GCS Outcome: $gcs_outcome <br />";
      echo "From IP Address: $ip <br />";
      echo "On " .date("Y-m-d") ." at " .date("h:i:sa");
      header("refresh:3; url=outcomes.php");
    } else {
      printf("Error: %s\n", mysqli_error($db_connect));
    }

    include('php_includes/footer.html');
    ?>


Form page code

    <?php
     $page_title = 'Outcomes';
     include('php_includes/header.html');
     ?>

    <div class="container-fluid" id="outcomes_data">
        <form class="form" action="insert_outcomes_data.php" method="post" name="outcomes_data" id="outcomes_data">
            <h3>Outcomes</h3>

            <div class="form-group">
                <div>Medical Record Number / Visit ID (Number 17 Characters):</div>
                <input class="form-control" id="mrn" name="mrn" type="text" maxlength="17">
            </div>

            <div class="form-group">
                <div>Additional NY Hospital Discharge Dispositions</div>
                <select class="form-control" id="add_hosp_dispo" name="add_hosp_dispo">
                    <option value="50">50 - Discharged to Shelter/Homeless</option>
                    <option value="51">51 - Discharged to Foster Care</option>
                    <option value="52">52 - Died-Full Code</option>
                    <option value="53">53 - Died-Withdrawal of Care</option>
                    <option value="54">54 - Died-DNR/DNI</option>
                    <option value="55">55 - Died-Brain Death</option>
                    <option value="56">56 - Transferred to TBI Rehabilitation Facility or Dedicated TBI Unit</option>
                    <option value="57">57 - Discharged or Transferred to Spinal Cord Injury Rehabilitation Facility or Dedicated Spinal Cord Injury Unit</option>
                    <option value="58">58 - Transfer out of State</option>
                </select>

                <a href="#add_hosp_dispo_info" data-toggle="collapse">More Info</a>

                <div id="add_hosp_dispo_info" class="collapse">
                    <ul>
                        <li>The disposition of the patient when discharged from the final hospital.</li>
                        <li>Full code: Patient was NOT a DNR/DNI (Do Not Resuscitate/Do Not Intubate) at the time of death, care was not withdrawn.</li>
                        <li>DNR/DNI: Patient had a Do Not Resuscitate/Do Not Intubate order, resuscitation was not provided at the time of death.</li>
                        <li>Care Withdrawn: Treatment was withdrawn or stopped prior to the patient's death. Documentation of "terminal weaning" or "discontinuation of life support" may suggest that care was withdrawn.</li>
                        <li>Brain Death Criteria: Select only if brain death criteria was met and the patient was declared dead using this criteria.</li>
                        <li>This field is crucial for modeling.</li>
                        <li><strong>Data Source:</strong> Discharge Summary, Nurses Notes, Case Manager/Social Service's Notes</li>
                    </ul>
                </div>
            </div>

            <div class="form-group">
                <div>Date of Alternate Level of Care Status</div>
                <input class="form-control" id="date_alt_lvl_cr_sts" name="date_alt_lvl_cr_sts" type="date">

                <a href="#date_alt_lvl_cr_sts_info" data-toggle="collapse">More Info</a>

                <div id="date_alt_lvl_cr_sts_info" class="collapse">
                    <ul>
                        <li>An order for discharge was written for the patient but because of social issues (i.e. homeless status, no bed available at an adult home or long term care facility) the patient remains at the facility only for shelter.</li>
                        <li>Collected as YYYY-MM-DD</li>
                        <li><strong>Data Source:</strong> Physician Order sheet, Social Work Notes, Nurses Notes</li>
                    </ul>
                </div>
            </div>

            <div class="form-group">
                <div>Actual Discharge Time</div>
                <input class="form-control" id="actual_discharge_time" name="actual_discharge_time" type="time">

                <a href="#actual_discharge_time_info" data-toggle="collapse">More Info</a>

                <div id="actual_discharge_time_info" class="collapse">
                    <ul>
                        <li>Collected as HH:MM military time.</li>
                        <li>This field is used to calculate the length of stay (time from admission to hospital discharge).</li>
                        <li><strong>Data Source:</strong> Nursing Notes</li>
                    </ul>
                </div>
            </div>

            <div class="form-group">
                <div>Actual Discharge Date</div>
                <input class="form-control" id="actual_discharge_date" name="actual_discharge_date" type="date">

                <a href="#actual_discharge_date_info" data-toggle="collapse">More Info</a>

                <div id="actual_discharge_date_info" class="collapse">
                    <ul>
                        <li>Collected as YYYY-MM-DD.</li>
                        <li><strong>Data Source:</strong> Nursing Notes</li>
                    </ul>
                </div>
            </div>

            <div class="form-group">
                <div>Glasgow Coma Score</div>
                <input class="form-control" type="number" id="gcs_outcome" name="gcs_outcome" min="3" max="15">

                <a href="#gcs_outcome_info" data-toggle="collapse">More Info</a>

                <div id="gcs_outcome_info" class="collapse">
                    <ul>
                        <li>GCS range is from 3-15.</li>
                        <li><strong>Data Source:</strong> Discharge Summary, Nurses Notes</li>
                    </ul>
                </div>
            </div>

            <p></p>

            <button type="submit" id="btn_outcomes_data">Insert Outcomes Data</button>
            <span id="status"></span>

        </form>
    </div>

<?php
include('php_includes/footer.html');
?>

1 个答案:

答案 0 :(得分:1)

SQL关键字不区分大小写(SELECT,FROM,WHERE等),但通常以全部大写形式编写。在某些设置中,表和列名称区分大小写。在你的情况下,MRN应该是mrn。这就是你没有插入数据的原因。