我的搜索表单有奇怪的问题。在输入关键字并执行搜索请求后,我得到空的参数值。参数仅在第二次按钮点击后出现在URL中
比如我在搜索栏中键入单词“东西”
我看到一个空值:
search.php?keyword=
这之后我输入关键字“其他”和我收到:
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>
您的文本输入的名称是'name =“search_keywords”'而当您正在寻找'keyword'时。 – Darren
另外为什么要混合'GET'&'POST'?它只会在第二轮设置(*当他们搜索*时),因为“POST”项有一个值。 – Darren
我了解我所做的GET和POST messup。我修好了它。一切都与GET并且这种行为已经消失。 –