php - PHP 表单操作不起作用且未更新查询字符串
问题描述
我正在尝试使用 MySQL 数据库和 PHP 为学校项目制作过滤器,但是每当我按下过滤器按钮时,它都不会执行操作,因此不会更新查询字符串。
它指的是我的主页的原因是因为这个块代码:
if (empty($_GET['page'])) {
$_GET['page'] = 'home';
}
if (empty($routes[$_GET['page']])) {
header('Location: index.php');
exit();
}
这是没有$GET['page']
通过的时候,它只会参考我的主页。
所以问题可能出在我的表单操作上,这显然是正确的: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>
当我按下过滤器按钮时,我在主页中,查询字符串是这样的:index.php?location=all
,所以$_GET[location]
我的项目有效。它只是没有在字符串中添加正确的页面。
解决方案
您的表单正在覆盖您的操作属性中的查询字符串参数。
不是将查询字符串放在操作中,而是添加一个隐藏字段
<form class="filter_form" method="get" action="index.php">
<!-- ... the rest of your form code -->
<input class="button filter_button" type="submit" value="filter" />
<input type="hidden" name="page" id="page" value="agenda" />
</form>
推荐阅读
- envoyproxy - 我可以在运行时更改故障注入配置特使代理吗?
- java - 高级交换方法(偶数和奇数元素交换)
- matplotlib - matplotlib barchart 固定外部位置和位置之间的填充
- sql - 当列非常大时,如何在oracle中删除表中的许多列?
- sql - 给定日期和sql中的公共值,从查询中提取行数据
- python - 无法导入熊猫:ImportError: cannot import name 'ops'
- twitter - 如何通过 Firefox 插件使用 twitter 进行身份验证
- azure - 如何推迟/安排从服务总线接收消息的重试策略?
- python-3.7 - 如何从python数组中删除括号?
- html - 是否有关于网页中的位置是否是放置光标以进行文本编辑的有效位置的规范?