我遇到mysql_num_rows问题。当我尝试登录时,会出现以下警告:
我搜索了那个错误,并且得到了它,这是因为错误的sql查询引起的。但我不确定。请帮忙。
$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 require_once 'class/userClass.php';?>
<?php $obj = new userClass;?>
<?php
if( isset( $_POST['login'] ) ){
$obj->login( $_POST,"home.php" );
}?>
答案 0 :(得分:2)
简单的解决方案:
$result = mysqli_query( $this->con, $sql );
和
$count = mysql_num_rows( $result );
$found_user = mysql_fetch_array( $result );
不要一起工作。
使用$ count和$ found_user的mysqli函数(你可以找到它们here)
答案 1 :(得分:0)
使用mysqli_num_rows
代替mysql_num_rows
和mysqli_fetch_array
代替mysql_fectch_array
。
你不能使用mysql和mysqli功能的组合