How does the PHP script handle errors when multiple search criteria are selected?
When multiple search criteria are selected, the PHP script should handle errors by checking if each criteria is valid and then constructing the query accordingly. If any criteria is missing or invalid, the script should display an error message to the user.
// Check if multiple search criteria are selected
if(isset($_POST['criteria1']) && isset($_POST['criteria2'])) {
// Validate criteria
if($_POST['criteria1'] != '' && $_POST['criteria2'] != '') {
// Construct query
$query = "SELECT * FROM table WHERE criteria1 = '{$_POST['criteria1']}' AND criteria2 = '{$_POST['criteria2']}'";
// Execute query
$result = mysqli_query($conn, $query);
// Display results or error message
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
// Display results
}
} else {
echo "No results found.";
}
} else {
echo "Please select valid criteria.";
}
} else {
echo "Please select multiple search criteria.";
}