I'm trying to make a filter using a MySQL database and PHP for a school project, but whenever I press my filter button, it doesn't execute the action so the querystring is not updated.
The reason it's referring to my homepage is because of this block code:
if (empty($_GET['page'])) {
$_GET['page'] = 'home';
}
if (empty($routes[$_GET['page']])) {
header('Location: index.php');
exit();
}
This is when there is no $GET['page']
passed, and it will just refer to my homepage.
So the problem probably lies with my form action, which is clearly correct: action="index.php?page=agenda"
<form class="filter_form" method="get" action="index.php?page=agenda">
<div class="location">
<p class="filter_by">filter by:</p>
<label for="location">location</label>
<select name="location" id="location">
<option value="all">-- Locations --</option>
<?php foreach($locations as $location): ?>
<option value="<?php echo $location['location']; ?>"
<?php
if(!empty($_GET['location'])){
if($_GET['location'] == $location['location']){
echo ' selected';
}
}
?>
>
<?php echo $location['location']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="checker_wrapper">
<div>
<input type="checkbox" name="check1" id="check1">
<label for="check1">skills only</label>
</div>
<div class="bottom_row">
<input type="radio" name="group" id="radio1">
<label for="radio1">day</label>
</div>
</div>
<div class="radio_wrapper">
<div>
<input type="checkbox" name="check2" id="check2">
<label for="check1">in group</label>
</div>
<div class="bottom_row">
<input type="radio" name="group" id="radio2">
<label for="radio2">evening</label>
</div>
</div>
<input class="button filter_button" type="submit" value="filter" />
</form>
When I press the filter button, I'm in the homepage and the querystring is like this: index.php?location=all
, so the $_GET[location]
for my project works. It's just not adding the correct page in the string.