mysql_fetch_array转换成mysqli_

时间:2014-05-09 18:49:18

标签: mysql

我试图将mysql_重写为mysqli_,但得到了2个错误

  

mysqli_fetch_array()期望参数1为mysqli_result,boolean given

  

mysqli_num_rows()期望参数1为mysqli_result,

为什么呢?我已将mysql_query("SELECT...)修复为mysqli_query($db, "SELECT..)和其他所有

<?php
ob_start();
session_start();

include('config/configuration.php'); 

if($_POST['Login'])
 {
  $UserName=$_POST['username'];
  $Password=md5($_POST['password']); 

  $UserQuery=mysqli_query($db, "SELECT Id, UserName, FirstName, LastName, Level FROM users WHERE UserName='$UserName' AND Password='$Password' AND IsActive=1 and level >= 3");

    $UserDetails=mysqli_fetch_array($UserQuery);        

        if(mysqli_num_rows($UserQuery))
            {       
                    $_SESSION['UserName'] = $UserDetails['UserName'] . ' (' .  $UserDetails['FirstName'] . ' ' . $UserDetails['LastName'] . ')';
                    $_SESSION['UserId'] = $UserDetails['Id'];
                    $_SESSION['Level']  = $UserDetails['Level'];

                mysqli_query("UPDATE users SET NumberOfLogin = NumberOfLogin + 1, LastLoginDate = NOW() WHERE Id = " . $_SESSION['UserId'] . " ");

1 个答案:

答案 0 :(得分:-1)

您的查询失败。

试试看这个问题:

if (!$UserQuery) {
    echo "MySQLi Error: " . mysqli_error($con);
    die();
}