【发布时间】:2015-09-30 13:34:08
【问题描述】:
我的网站有一个搜索表单,效果非常好,但后来我更改了整个登录系统,这导致我的网站出现了一些错误。现在我似乎无法修复的唯一错误是我网站中的搜索表单。我认为这很奇怪,因为表单不使用登录表单中的任何变量。当我在测试以找出问题时,我发现当我的搜索脚本的一部分进入 while 循环时,它会在我身上中断。如果您有任何建议或帮助,将不胜感激。我将在下面提供我的代码。
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 中给出的 null 第 45 行
【问题讨论】:
-
错误是什么?你调试了吗?\
标签: php mysql forms loops search