【发布时间】:2019-01-26 13:11:50
【问题描述】:
我遇到了这个问题,当我搜索一个单词时,它不会显示并且会弹出这个错误
警告:mysqli_fetch_array() 期望参数 1 为 mysqli_result,布尔值在 C:\xampp\htdocs\public_html\filterdata.php 第 213 行给出)。
只显示过滤前的表格
<?php
include("auth_admin.php");
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `lcho_dengue_activities` CONCAT(`id`, `month`, `year`, `dengue_ind1`) where `month`= '".$valueToSearch."'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `lcho_dengue_activities`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "lcho_login");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<form action="filterdata.php" method="post">
<input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
<input type="submit" name="search" value="Filter"><br><br>
<table>
<tr>
<th>Id</th>
<th>Month</th>
<th>Year</th>
<th>dengue_ind1</th>
</tr>
<!-- populate table from mysql database -->
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['month'];?></td>
<td><?php echo $row['year'];?></td>
<td><?php echo $row['dengue_ind1'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
//while($row = mysqli_fetch_array($search_result)) 是我的第 213 行
我尝试将 $search_result 更改为 $query 并发生同样的错误。
【问题讨论】:
-
警告:您对SQL Injections 持开放态度,应该真正使用参数化的prepared statements,而不是手动构建查询。它们由PDO 或MySQLi 提供。永远不要相信任何类型的输入,尤其是来自客户端的输入。即使您的查询仅由受信任的用户执行,you are still in risk of corrupting your data。