I keep getting this error message when I try to add an AND condition to the end of a existing select statement. I haven't be able to work out why!
The error message is
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\xampp\htdocs\tworesults.php on line 49
and the code is
<?php
// Check that the form has been submitted
if ($_POST) {
//Store the form data in variables
$form_library_id = $_POST['library_id'];
//Trim any trailing and leadin spaces from the form data
$form_library_id = trim($form_library_id);
//Open a connect to the database
$link = mysqli_connect('localhost', 'student', 'mmst12009', 'assignment3');
//Define a query
$query = "SELECT library_name, library_city
FROM libraries";
if ($form_library_id != 'any') {
$query .= " AND library_id = $form_library_id";
}
$result = mysqli_query($link, $query);
mysqli_close($link);
echo <<<END
<table border="0">
<tr>
<th>Library Name</th>
<th>Library City</th>
</tr>
END;
While ($row = mysqli_fetch_array($result)) {
$library_name = $row['library_name'];
$library_city = $row['library_city'];
echo <<<END
<tr>
<td>$library_name</td>
<td>$library_city</td>
</tr>
END;
}
echo "</table>";
}
?>