当我运行此查询时,我收到了
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/morgan58/public_html/wow/includes/index/index_admin.php on line 188
SELECT * FROM characters WHERE id=5
Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in /home/morgan58/public_html/wow/includes/index/index_admin.php on line 194
Query正在运行,它正在试图选择正确的信息,但对于实际输出,它给了我一个fetch_array错误;如果有人能够看到错误所在的位置,我将非常感激。谢谢。
<?php
$adminid= $admin->get_id();
$characterdb= 'characters';
$link = mysqli_connect("$server", "$user", "$pass", "$characterdb");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT * FROM characters WHERE id=$adminid";
$result = mysqli_query($link, $query);
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
echo $query;
echo $row['name'];
}
mysqli_free_result($result);
mysqli_close($link);
?>
答案 0 :(得分:3)
您的查询中存在错误,因此mysqli_query()
返回false。在使用之前检查它是否有效:
if ($result) {
/// your code
}else {
// your query failed
die("Error: ".mysqli_error($link)); // will print your error
}
答案 1 :(得分:0)
$query = "SELECT * FROM characters WHERE id=$adminid";
//further correction is single quote your variable in this case you are increase success run of your query
$query = "SELECT * FROM characters WHERE id='$adminid'";
$result = mysqli_query($link, $query);
// its good you check before you leap
if($result){
// your process
} else {
echo "Unable to find given admin id";
}