0

Im trying to rewrite mysql_ into mysqli_, but got 2 errors

mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given

and

mysqli_num_rows() expects parameter 1 to be mysqli_result,

why? Ive fixed mysql_query("SELECT...) into mysqli_query($db, "SELECT..) and all others

<?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'] . " ");
Adalbert
  • 7
  • 1
  • 2
  • possible duplicate of ["mysql\_fetch\_array() expects parameter 1 to be resource, boolean given" in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-selec) – John Conde May 09 '14 at 18:49
  • I think its ok `$db = mysqli_connect($host, $db_user, $db_password, $database);` – Adalbert May 09 '14 at 19:14

1 Answers1

-1

Your query is failing.

Try this to see the issue:

if (!$UserQuery) {
    echo "MySQLi Error: " . mysqli_error($con);
    die();
}
Ruby
  • 528
  • 3
  • 14
  • Yeah, the query failed, thanks to you I've managed to fix it. Thank you very much again. The problem was I didnt noticed, that database contain `Id, UserName, Level`, but no `FirstName and LastName`. – Adalbert May 09 '14 at 19:27