【发布时间】:2016-09-20 16:39:42
【问题描述】:
我的导航页面中有这个输入框和按钮
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 $输出 = '';
<!--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
我有开发工具并没有出现任何错误。 有什么想法吗?
【问题讨论】:
-
您正在混合数据库驱动程序。
mysqli_num_rows无法与mysql_*一起使用,请将所有内容更新为mysqli。也可以使用参数化查询。 -
我把所有的mysql都改成mysqli了,还是不行。还是一样的结果??
-
您是否在某处回显了生成的查询并手动尝试以确保它确实返回了您认为应该返回的内容?
-
用新代码更新问题。