php 警告:mysqli_fetch_row() 期望参数 1 是 mysqli_result,布尔值在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31530515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in
提问by ddfg
I know that there's been threads about it, but those didn't help me. Anyways I'm new in PHP and I was creating login system when I got stuck. I can't understand why is it giving me this error: Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in
我知道有关于它的线索,但那些对我没有帮助。无论如何,我是 PHP 新手,当我卡住时我正在创建登录系统。我不明白为什么它给我这个错误:警告:mysqli_fetch_row() 期望参数 1 是 mysqli_result,布尔值在
Code is here:
代码在这里:
<?php
session_start();
if(isset($_POST['username'])){
include_once("dbconnect.php");
$usname = strip_tags($_POST["username"]);
$paswd = strip_tags($_POST["password"]);
$usname = mysqli_real_escape_string($dbCon, $usname);
$paswd = mysqli_real_escape_string($dbCon, $paswd);
$paswd = md5($paswd);
$sql = "SELECT id, fooruminimi, password FROM liikmed WHERE username = '$usname' AND aktiveeritud = '1' LIMIT 1";
$query = mysqli_query($dbCon, $sql);
$row = mysqli_fetch_row($query);
$uid = $row[0];
$dbUsname = $row[1];
$dbPassword = $row[2];
if($usname == $dbUsname && $paswd == $dbPassword){
//Sessioni avamine
$_SESSION['username'] = $usname;
$_SESSION['id'] = $uid;
//Suunamine
header("Location: user.php");
}
else{
echo "<h2> Vale kasutajanimi v?i parool!</h2>";
}
}
?>
回答by Abdulla Nilam
This will occur with 2 main reason
这将有两个主要原因
mysqli_connect()
is failed to connectmysqli_query()
return nothing
mysqli_connect()
连接失败mysqli_query()
什么都不回
Check in your code
签入您的代码
$dbCon = mysqli_connect("localhost","my_user","my_password","my_db");
and check $sql
returns data
并检查$sql
返回数据
$sql = "SELECT id, fooruminimi, password FROM liikmed WHERE username = '$usname' AND aktiveeritud = '1' LIMIT 1";
回答by Shri Suresh
It means your query failed and returned false.
这意味着您的查询失败并返回 false。
Recheck that to make sure it's working.
重新检查以确保它正常工作。
mysqli_query($dbcon, $sql) or die(mysqli_error($dbcon));
回答by bish
Check you credentials and your select statement for mistakes, your sourcecode looks good for me.
检查您的凭据和您的选择语句是否有错误,您的源代码对我来说看起来不错。
Problem is that your mysql_query
in the following part returns a false
meaning the execution of your query has failed.
问题是您mysql_query
在以下部分返回了一个false
含义,即您的查询执行失败。
$sql = "SELECT id, fooruminimi, password FROM liikmed WHERE username = '$usname' AND aktiveeritud = '1' LIMIT 1";
$query = mysqli_query($dbCon, $sql);
So $query
is filled with the boolean false
instead of an mysql_result
object which is needed for the next line
所以$query
填充了布尔值false
而不是mysql_result
下一行所需的对象
$row = mysqli_fetch_row($query);
You should insert an if
clause before this line to check this like:
您应该if
在此行之前插入一个子句来检查:
if($query === false) {
echo "error while executing mysql: " . mysqli_error($dbcon);
} else {
// move on with your normal skript
}