我的导航页面中有这个输入框和按钮
form class="navbar-form"
div class="form-group"
form action="search.php" method="POST">
input type="text" class="form-control" name="search"
placeholder="Search for Products..."
input type="submit" value="Submit"
/form
/div
/form
位于index.php页面的顶部和search.php中 $ output ='';
<!--collect -->
if(isset($_POST['search'])) {
$searchQ = $_POST['search'];
$searchQ = preg_replace("#[^0-9a-z]#i","",$searchQ);
$query = mysql_query("SELECT * FROM products WHERE title LIKE
'%$searchQ%' OR part_number LIKE '%$searchQ%' OR stock_code LIKE
'%$searchQ%' OR form_factor LIKE '%$searchQ%' ") or die("could not
search!");
$count = mysqli_num_rows($query);
if($count == 0) {
$output = '"There was no search results"';
} else {
while($row = mysql_fetch_array($query)) {
$title = $row['title'];
$partNumber = $row['part_number'];
$stockCode = $row['stock_code'];
$formFactor = $row['form_factor'];
$id = $row['id'];
$output .= '<div>'.$title.' </div>';
}
}
}
当我点击按钮时,网址会从 http://localhost/alphacomponents.co.uk/index.php至http://localhost/alphacomponents.co.uk/index.php?search=Asus
我开发了工具,没有出现任何错误。 有什么想法吗?
答案 0 :(得分:0)
我想发表评论,但没有足够的声誉。
是问题,因为你在另一个表单中有一个表单?因此,您提交外部表格 - 这不是您要提交的表格?
您可以尝试下面的表单,然后检查它是否正确导航到search.php页面。
<form class="navbar-form" action="search.php" method="POST">
<div class="form-group">
<input type="text" class="form-control" name="search" placeholder="Search for Products...">
<input type="submit" value="Submit">
</div>
答案 1 :(得分:0)
主要问题是网址从http://localhost/alphacomponents.co.uk/index.php转到http://localhost/alphacomponents.co.uk/index.php?search=Asus
应该转到http://localhost/alphacomponents.co.uk/search.php。
您需要删除嵌套表单。就这样说:
form class =&#34; navbar-form&#34;行动=&#34;的search.php&#34;方法=&#34; POST&#34;