我遇到了 mysql_num_rows 的问题。当我尝试登录时,会出现以下警告:
警告:mysql_num_rows() 期望参数 1 是资源,在 #no 行的 path/to/userClass.php 中给出的对象。
我搜索了那个错误,得到了那个错误,这是由于错误的 sql 查询引起的。但我不确定。请帮忙。
用户类.php
登录功能
$sql = "SELECT id, username FROM `user` WHERE username = '$username' AND hashed_password ='$password'";
$result = mysqli_query( $this->con, $sql );
if ( !$result ) die ("Database query failed" . mysql_error());
else{
$count = mysql_num_rows( $result );
if( $count == 1 ){
$found_user = mysql_fetch_array( $result );
$_SESSION['user_id'] = $found_user['id'];
$_SESSION['username'] = $found_user['username'];
header( "Location:{$location}" );
}else{
//username/password combo was not found in the database
$this->pass_notverified = "Username/password incorrect.";
return;
}
}
头文件.php
<?php require_once 'class/userClass.php';?>
<?php $obj = new userClass;?>
<?php
if( isset( $_POST['login'] ) ){
$obj->login( $_POST,"home.php" );
}?>