這是我的搜索代碼,當我點擊搜索按鈕時,它會給出所有值的輸出,而不是搜索特定的產品標題。搜索不能使用php
任何幫助?
<?php include("config.php");
mysqli_select_db("onlinegrocery");
$output = "";
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = "SELECT * FROM tbl_product WHERE product_title LIKE '%$searchq%'";
$sql=mysqli_query($con,$query);
$count = mysqli_num_rows($sql);
if($count == 0) {
$output = 'Nothing Found';
}
else {
while($row = mysqli_fetch_array($sql)){
$product_title = $row['product_title'];
$id = $row['product_id'];
$output .= '<div> '.$product_title.' </div>';
}
}
}
?>
<form action="index.php" method="post">
<input type="text" class="form-control" placeholder="Search">
<div class="input-group-btn">
<button class="btn btn-default" type="submit" name="search"><i class="glyphicon glyphicon-search"></i></button>
</div>
</form>
<?php echo("$output");?>
我認爲' 「#[^ 0-9A-Z] * I」'你不應該從搜索查詢中刪除空格。 '「#[^ 0-9a-z \ s] #i」' – jekaby