Php 参数仅在单击第二个按钮后显示在URL中
我的搜索表有奇怪的问题。在我输入关键字并执行搜索请求之后,我得到了空的参数值 例如,我在搜索字段中键入单词“某物” 我看到一个空值:Php 参数仅在单击第二个按钮后显示在URL中,php,Php,我的搜索表有奇怪的问题。在我输入关键字并执行搜索请求之后,我得到了空的参数值 例如,我在搜索字段中键入单词“某物” 我看到一个空值: search.php?keyword= 在此之后,我输入关键字“else”,并收到: search.php?keyword=something而不是search.php?keyword=else 他们以某种方式“后退一步” 我试图用print_r和var_dump进行调试,但我只能打印一些无法解释问题的值 我是否错过了一些非常琐碎的事情 以下是我所拥有的: 我的
search.php?keyword=
在此之后,我输入关键字“else”,并收到:
search.php?keyword=something
而不是search.php?keyword=else
他们以某种方式“后退一步”
我试图用print_r和var_dump进行调试,但我只能打印一些无法解释问题的值
我是否错过了一些非常琐碎的事情
以下是我所拥有的:
我的班级功能:
public function show_search_result() {
$this->search_keywords = strip_tags($_GET['keyword']);
$this->_db->query("SELECT * from posts WHERE post_title LIKE '%$this->search_keywords%' OR post_content LIKE '%$this->search_keywords%' LIMIT 100");
$this->rows_results_found = $this->_db->resultset();
}
<form action="search.php?keyword=<?php
if (isset($search_results->rows_results_found) && isset($_POST['search_requested'])) {
print strip_tags($_POST['search_keywords']);
}
?>" method="post">
<input type="hidden" name="search_requested">
<input type="text" name="search_keywords" value="<?php
if (isset($search_results->rows_results_found) && isset($_POST['search_requested'])) {
print strip_tags($_POST['search_keywords']);
}
?>"><input type="submit" value="Search">
</form>
和我的表格:
public function show_search_result() {
$this->search_keywords = strip_tags($_GET['keyword']);
$this->_db->query("SELECT * from posts WHERE post_title LIKE '%$this->search_keywords%' OR post_content LIKE '%$this->search_keywords%' LIMIT 100");
$this->rows_results_found = $this->_db->resultset();
}
<form action="search.php?keyword=<?php
if (isset($search_results->rows_results_found) && isset($_POST['search_requested'])) {
print strip_tags($_POST['search_keywords']);
}
?>" method="post">
<input type="hidden" name="search_requested">
<input type="text" name="search_keywords" value="<?php
if (isset($search_results->rows_results_found) && isset($_POST['search_requested'])) {
print strip_tags($_POST['search_keywords']);
}
?>"><input type="submit" value="Search">
</form>
一个简单的代码
您的问题是,当您发送表单时,它会将关键字保存到第二次发送。将您的方法从post更改为get。此外,我建议您使用一个框架来轻松快速地编码。其中包括symfony2、laravel当您查找关键字时,您的文本输入的名称是name=“search_keywords”
。另外,您为什么要混合GET
和POST
?它只会在第二轮设置(当他们搜索时),因为POST
项有一个值。我理解我所做的GET和POST消息。我修好了。GET一切正常,这种行为消失了。你需要改进这个答案,它超出了低质量。是的,对不起我在打电话。@wwwanaya我在打电话?认真地这是互联网,它不需要实时交互。没人在乎你是否在打电话,只要把电话打完,然后写一个有用的答案就行了。还是有人在你打电话的时候强迫你写回信?!我在手机应用程序上,不是在打电话。