[英]Search results are not returning from sql query using search button
I'm trying to get a search functionality working. 我正在尝试使搜索功能正常工作。 When the user clicks in a box and searches something the page should be able to display the results with the word included, otherwise there is a simple message that no result could be found.
当用户单击一个框并搜索内容时,页面应该能够显示包含单词的结果,否则将显示一条简单消息,即找不到结果。 At the moment nothing is displaying (no errors either) and I do not know why.
目前没有任何显示(也没有错误),我也不知道为什么。
Here is what I have so far. 这是我到目前为止所拥有的。 Any help would be appreciated.
任何帮助,将不胜感激。
1) On my index.php page there is the search box and search button. 1)在我的index.php页面上,有搜索框和搜索按钮。
<li>
<div id = "search">
<form id = "search-form" action="search_results.php" method="post">
<input type="text" name= "find" placeholder= "Search..." />
<input type="button" name = "search" value="search" />
</form>
</div>
</li>
2) When the user types what they want, they are taken to search_results.php where the searching happens. 2)当用户键入他们想要的内容时,会将他们带到进行搜索的search_results.php。 A list of product names should be returned if the search was successful.
如果搜索成功,则应返回产品名称列表。
<div class = "main-content">
<h1> Search Results </h1>
<?php
include 'dbconnect.php';
$output ='';
if (isset($_get['find'])){
$searchq = $_get['find'];
$query = mysqli_query($con, "SELECT * FROM products WHERE prodname LIKE '%". $searchq . "%'");
$count = mysqli_num_rows($query);
if($count == 0){
echo "There was no search results !";
}
else{
while($row = mysqli_fetch_array($query)){
$prodname = $row['prodname'];
$output ='<div> '.$prodname.'</div>';
echo $output;
}
}
} // end of outer if
mysqli_close($con);
?>
</div>
You are doing post
and using the $_get
in your search_results.php
file which is wrong method. 您正在
post
并在search_results.php
文件中使用$_get
,这是错误的方法。
As you are using the post
method in your action you should get the values accordingly 当您在操作中使用
post
方法时,您应该相应地获取值
ie, 即
if (isset($_POST['find'])){
$searchq = $_POST['find'];
#Your If Condition
}
else
{
#Your Else Part
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.