我正在嘗試創建一個網站,但我的通配符搜索查詢不斷給我提出問題。非功能性php通配符搜索查詢
它不顯示任何錯誤,但結果顯示爲空白。 你可以在這裏看到它在這個網站:luke.dx.am/Search.php
她是我的搜索欄的代碼。
<!-- Custom Search -->
<form action="Search.php" method="post">
<input type="text" name="search" placeholder="Search"/>
<input type="submit" value=">>"/>
</form>
這是我的代碼,執行搜索查詢。
<?php
$output = '';
$searchq = '';
$search_query = '';
$search_results = '';
$result = '';
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
//Query for the search engine
$search_query = "SELECT Item.Item, Category.Category, Colour.Colour,
Description.Description, products.Price, products.Stock, products.date,
Sexs.Sex, Sizes.Size, Designers.Designer, Designers.Email,
Designers.Phone, Designers.Address, Image.Image
FROM products
INNER JOIN Category
ON Category.CatagoryCode=products.CatagoryCode
INNER JOIN Colours
ON Colour.ColourCode=products.CatagoryCode
INNER JOIN Description
ON Description.DescriptionCode=products.DescriptionCode
INNER JOIN Designers
ON Designers.DesignerCode=products.DescriptionCode
INNER JOIN Sexs
ON Sexs.SexCode=products.SexCode
INNER JOIN Image
ON Image.ImageCode=products.ItemCode
INNER JOIN Item
ON Item.ItemCode=products.ItemCode
INNER JOIN Sizes
ON Sizes.SizeCode=products.SizeCode
WHERE Item.Item LIKE '%$searchq%' OR Category.Category LIKE '%$searchq%'
OR Colour.Colour LIKE '%$searchq%' OR Description.Description LIKE
'%$searchq%' OR Sexs.Sex LIKE '%$searchq%' OR Sizes.Size LIKE
'%$searchq%' OR Designers.Designer LIKE '%$searchq%'";
$search_results=mysqli_query($con, $search_query);
if($result == FALSE) {
?><p>Error</p><?php
die(mysql_error()); // TODO: better error handling
}else{
//Runs in a while loop
while($output=mysqli_fetch_array($result))
{
?>
對不起,代碼的絕對牆。
已經有mysql的警告顯示在您的主頁 –
它應該是search_result吧? –
@result我認爲 –