得到一个恼人的警告:mysqli_fetch_array()

时间:2014-05-29 20:01:15

标签: php mysqli

请注意:

我已经检查了“mysql(i)_fetch_array() expects parameter 1 to be resource/mysqli_result, boolean given” in select中的答案,但我仍然有这个奇怪的警告

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\XXXXXXXX\v2\dashboard\inc.query.members.php on line 19

我试图在stackOverflow中搜索解决方案,但我无法确定我在哪里犯错!

这是我的代码:

<?php

    // 10. we import the user id from the login page query
    //  $userId is in the index.php which this file is included in it;

  // 20. we get the user information from member table in db
    $s = "SELECT * FROM `members` WHERE `id` = '$userId'"; // select
    $q = mysqli_query($link, $s);                                   // run query
    if(! $q)
    {
    die("SQL Error: " . mysqli_error($link));
    }
    $p = mysqli_prepare($link, $s);                             // prepare
    $e = mysqli_stmt_execute($p);                                   // execute
    $r = mysqli_stmt_store_result($p);                      // store results
    $n = mysqli_stmt_num_rows($p);                              // number of row
    if($n == 1)
    {
        while($n = mysqli_fetch_array($q))
        {
            // 30. we get the current date & time to update the last_activity
            $currentDateTime            = Date('Y-m-d H:i:s');

            // 40. we assign user data in varibales
            $userId                                 = $n['id'];
            $userName                           = $n['user_name'];
            $userFirstName                  = $n['first_name'];
            $userMiddleName                 = $n['middle_name'];
            $userlastName                   = $n['last_name'];
            $userGender                         = $n['gender'];
            $userYOB                                = $n['yob'];
            $userCell                           = $n['cell'];
            $userAvatar                         = $n['avatar_url'];
            $userRegistrationDate   = $n['registration_date'];
            $userLastActivity           = $n['last_activity'];
            $passwordUpdated                = $n['password_updated'];

            // 50. we update the last_activity with $currentDateTime
            $s = "UPDATE `members` SET `last_activity`= '$currentDateTime' WHERE `id` = '$userId'";
            $q = mysqli_query($link, $s);

        } // end of while
    } //if($n == 1)

?>

此代码是index.php页面的一部分,在index.php中我需要数据库连接。

除了警告,我从数据库中获取信息,我可以echo到页面。此外,我可以更新并插入数据库。

仅供参考,此警告仅在我的xampp本地服务器中显示,而在生产服务器中则不会显示。

请您说明我该怎么办才能收到这个恼人的警告。

提前致谢...

0 个答案:

没有答案