我的網站有一個搜索表單,它工作得很好,但是我改變了整個登錄系統,導致我的網站出現了一些錯誤。現在唯一不能解決的錯誤就是我網站中的搜索表單。我認爲這很奇怪,因爲表單不使用登錄表單中的任何變量。當我進行測試以發現問題時,我發現當我的搜索腳本的部分進入while循環時,它會打斷我。如果您有任何建議或幫助,將不勝感激。我將在下面提供我的代碼。當我進入While循環時,PHP搜索無法正常工作
hub.php
<?php
// this file connects to the database
include("includes/connect.inc.php");
session_start();
if (isset($_SESSION['id'])) {
$uid = $_SESSION['id'];
}
//If the search input was submitted then run
if(isset($_POST['search'])){
// turn that the user searched into a varible
$searchQ = $_POST['search'];
// delete any symbols for security
$searchQ = preg_replace("#[^0-9a-z]#i", "", $searchQ);
// Define varibles before the loop
$searchArray = array();
$searchIndex = 0;
// Search through these columns inside the main database
$searchQuery = mysqli_query("SELECT * FROM database WHERE
title LIKE '%" . mysqli_escape_string($searchQ) . "%'
");
// count the number of results
$searchCount = mysqli_num_rows($searchQuery);
if($searchCount != 0){
while($row = mysqli_fetch_array($searchQuery)){
$titleSearch = $row['title'];
$dateSearch = $row['date'];
// buile the array which will hold all the results
$searchArray[$searchIndex] = array($titleSearch, $dateSearch);
$searchIndex++;
}
}
}
// End of search php
<form id="search" action="hub.php" method="POST">
<div id="searchIcon"></div>
<input type="search" name="search" placeholder="Search">
</form>
這裏是連接文件|它用於一堆其他形式和工作正常的循環。
<?php
$host = "MYHOSTINGDOMAIN";
$username = "MYUSERNAME";
$password = "MYPASSWORD";
$db = $username;
$connect = mysqli_connect($host, $username, $password, $db) or die(mysqli_connect_error());
我得到這個錯誤
警告:mysqli_query()預計至少2個參數,1 /services/webpages/d/i/digitalicon.ca/public/hub.php給出第42行
警告:mysqli_num_rows()預計參數1被mysqli_result, 空在/services/webpages/d/i/digitalicon.ca/public/hub.php給定上 線45
錯誤是什麼?你有沒有調試過?\ –