我的网站有一个搜索表单,它工作得很好,但是我改变了整个登录系统,导致我的网站出现了一些错误。现在唯一不能解决的错误就是我网站中的搜索表单。我认为这很奇怪,因为表单不使用登录表单中的任何变量。当我进行测试以发现问题时,我发现当我的搜索脚本的部分进入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
错误是什么?你有没有调试过?\ –