$insertQuery = "INSERT INTO appointment
( appointmentID
, doctorid
, appointmentDate
, symptoms
, patientid
, time
)
SELECT '" . $id . "'
, n.doctorid
, '" . $date . "'
, '". $symptoms ."'
, p.patientid
FROM ( SELECT e.doctorid
FROM doctors e
WHERE e.doctorName LIKE '" . $docName . "'
LIMIT 1
) d
CROSS
JOIN ( SELECT q.patientid
FROM patient q
WHERE q.patientName LIKE '" . $nameOfUser ."'
LIMIT 1
) p ";
This statement is subject to SQL Injection. To mitigate that, you'd either need to escape "unsafe" values that are included in the SQL text, or use a prepared statement with bind placeholders.
Assuming that you are using procedural style functions of the mysqli interface, and the connection is named $con
$insertQuery = "INSERT INTO appointment
( appointmentID
, doctorid
, appointmentDate
, symptoms
, patientid
, time
)
SELECT '" . mysqli_real_escape_string($con, $id) . "'
, n.doctorid
, '" . mysqli_real_escape_string($con, $date) . "'
, '" . mysqli_real_escape_string($con, $symptoms) ."'
, p.patientid
FROM ( SELECT e.doctorid
FROM doctors e
WHERE e.doctorName LIKE '" . mysqli_real_escape_string($con, $docName) . "'
LIMIT 1
) d
CROSS
JOIN ( SELECT q.patientid
FROM patient q
WHERE q.patientName LIKE '" . mysqli_real_escape_string($con, $nameOfUser) ."'
LIMIT 1
) p ";
A prepared statement would replace the literals with bind placeholders:
$insertQuery = "INSERT INTO appointment
( appointmentID
, doctorid
, appointmentDate
, symptoms
, patientid
, time
)
SELECT ?
, n.doctorid
, ?
, ?
, p.patientid
FROM ( SELECT e.doctorid
FROM doctors e
WHERE e.doctorName LIKE ?
LIMIT 1
) d
CROSS
JOIN ( SELECT q.patientid
FROM patient q
WHERE q.patientName LIKE ?
LIMIT 1
) p ";