回声不成功的错误

时间:2017-04-03 17:01:34

标签: php android sql database

下面的代码应该连接到应用程序并将数据插入从用户输入的数据库中。但是,当我运行代码时,我发现了一个奇怪的错误'解析错误:语法错误,意外'插入'在...&#39 ;.对我来说,这个错误告诉我回声'插入成功',以某种方式导致代码崩溃,我误解了错误说的是什么?有人可以告诉我如何修复代码吗?

<?php
    require "conn.php";

    $patient_name = $_POST["patient_name"];
    $doctor_name = $_POST["doctor_name"];
    $check_in_date = $_POST["check_in_date"];
    $room_number = $_POST["room_number"];
    $bed_number = $_POST["bed_number"];
    $notes = $_POST["notes"];
    $time = $_POST["time"];

    $mysql_qry = "insert into patients2
    (patient_name, doctor_name, check_in_date, room_number, bed_number, notes, time) 
    values ('$patient_name', '$doctor_name', '$check_in_date', '$room_number', '$bed_number', '$notes', '$time';);                  

    if($conn->query($mysql_qry) === TRUE) {
        echo "Insert successful";
    }
    else{
        echo "Error: " . $mysql_qry . "<br>" . $conn->error;
    }
    $conn->close();
?>

2 个答案:

答案 0 :(得分:1)

你错过了封闭的双引号并且有一个额外的分号:

这个:

$mysql_qry = "insert into patients2
    (patient_name, doctor_name, check_in_date, room_number, bed_number, notes, time) 
    values ('$patient_name', '$doctor_name', '$check_in_date', '$room_number', '$bed_number', '$notes', '$time';);

需要如下:

$mysql_qry = "insert into patients2
    (patient_name, doctor_name, check_in_date, room_number, bed_number, notes, time) 
    values ('$patient_name', '$doctor_name', '$check_in_date', '$room_number', '$bed_number', '$notes', '$time')";
    //                                                                                                            ^

答案 1 :(得分:1)

你已经使用了额外的;在您的查询中。它不应该在那里。 你的查询应该是这样的:

$mysql_qry = "insert into patients2
(patient_name, doctor_name, check_in_date, room_number, bed_number, notes, time) 
values ('$patient_name', '$doctor_name', '$check_in_date', '$room_number', '$bed_number', '$notes', '$time')";