2

The code below is supposed to connect to an application and insert data into the database that has been entered from the user. However I get a strange error when I run the code it says 'Parse error: syntax error, unexpected 'Insert' in...'. To me this error is telling me that the echo 'Insert successful', is somehow causing the code to crash, am i misinterpreting what the error is saying? Could someone show me how I can fix the code?

<?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();
?>
MonBoy175
  • 75
  • 8

2 Answers2

1

you missing the enclosing double quotes and have an extra semi-colon :

this :

$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';);

needs to be as follows:

$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')";
    //                                                                                                            ^
hassan
  • 7,812
  • 2
  • 25
  • 36
1

you have used a extra ; inside your query. it should not be there. your query should be like this:

$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')";