I am new to PHP and MySQL and struggle to extract data from db based on html search form containing several fields. 1st field (*required) = select with options (select name = area_name
), 2nd = input type: school name, 3rd = date, 4-5th = time_from, time_to. Question: how may I extract lecturers' names based on above fields?
Below is the PHP code (ignore db connect, it's working):
if (!empty($_REQUEST['term'])) {
$term = mysql_real_escape_string($_REQUEST['term']);
(line 8)
$sql = mysqli_query("SELECT lecturer_name, city, phone, e-mail * FROM
area_name where area_name LIKE '$search'") UNION ("SELECT * FROM school
where school_name LIKE '$search'") UNION ("SELECT * FROM schedule where
date LIKE '$search'") UNION ("SELECT * FROM schedule where time_from
LIKE '$search'") UNION ("SELECT * FROM schedule where time_to LIKE
'$search'");
$r_query = mysqli_query($sql);
echo "<table border='1' cellpadding='5'>";
echo "<tr> <th>Lecturer Name</th> <th>City</th> <th>Phone</th>
<th>Email</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
while ($row = mysql_fetch_array($r_query)){
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['lecturer_name'] . '</td>';
echo '<td>' . $row['city'] . '</td>';
echo '<td>' . $row['phone'] . '</td>';
echo '<td>' . $row['email'] . '</td>';
echo "</tr>";
}
// close table>
echo "</table>";
}
$conn->close();
In the result, have the following error:
Parse error: syntax error, unexpected 'UNION' (T_STRING) in D:\XAMPP\htdocs\trv\search_lecturer.php on line 8
I can't get how to connect html field names with mysql. Will really appreciate any help!