可捕獲的致命錯誤:類mysqli_result的對象無法轉換爲字符串in /opt/lampp/htdocs/internshala/controller/signup.php第40行警告:mysqli_num_rows()期望參數1爲mysqli_result,在38行中的/opt/lampp/htdocs/internshala/controller/signup.php中給出的數組
if(isset($_POST['btn-login']))
{
$username = trim($_POST['username']);
$username = strip_tags($username);
$username = htmlspecialchars($username);
$qry="select id,pwd,username from users where username='".$_POST['username']."'";
$res=mysqli_query($conn,$qry);
$row=mysqli_fetch_array($res);
$count = mysqli_num_rows($row); // if uname/pass correct it returns must be 1 row
//echo $_POST['pwd'];
echo $res;
echo $count;
echo $row;
if($count == 1 && $row['pwd']==$_POST['pwd']) {
echo "djfgk";
$_SESSION['username'] = $row['username'];
$_SESSION['userid']=$row['id'];
header("Location: userdashboard.php");
} else {
$errMSG = "Incorrect Credentials, Try again...";
echo $errMSG;
}
}
不要直接發佈變量。 SQL注入!!!! – Akintunde007
可能的複製的[PHP和MySQL:mysqli的\ _num \ _rows()預計參數1是mysqli的\ _result,給定的boolean(http://stackoverflow.com/questions/2546314/php-mysql-mysqli-num-rows -expects參數-1-待mysqli的-結果布爾) – Naruto