一尘不染

mysqli_fetch_array()期望参数1为mysqli_result,在[duplicate]中给出布尔值

mysql

这个问题已经在这里有了答案

mysqli_fetch_assoc()期望参数/调用成员函数bind_param()错误。如何获取并修复实际的mysql错误? (1个答案)

7年前关闭。

我在检查数据库中是否已存在Facebook
User_id时遇到了一些麻烦(如果不存在,则应将用户作为新用户接受,否则仅加载canvas应用程序)。我在托管服务器上运行了它,没有问题,但是在我的本地主机上,它给了我以下错误:

mysqli_fetch_array()期望参数1为mysqli_result,布尔值在

这是我的代码:

<?
$fb_id = $user_profile['id'];
$locale = $user_profile['locale'];

if ($locale == "nl_NL") {
    // Checking User Data @ WT-Database
    $check1_task = "SELECT * FROM `users` WHERE `fb_id` = " . $fb_id . " LIMIT 0, 30 ";
    $check1_res = mysqli_query($con, $check1_task);
    $checken2 = mysqli_fetch_array($check1_res);
    print $checken2;
    // If the user does not exist @ WT-Database -> insert
    if (!($checken2)) {
        $add = "INSERT INTO users (fb_id, full_name, first_name, last_name, email) VALUES ('$fb_id', '$full_name', '$first_name', '$last_name', '$email')";
        mysqli_query($con, $add);
    }
    // Double-check, the user won't be able to load the app on failure inserting to the database
    if (!($checken2)) {
        echo "Excuse us " . $first_name . ". Something went terribly wrong! Please try again later!";
        exit;
    }
} else {
    include ('sorrylocale.html');
    exit;
}

我读过它与我的查询错误有关,但是它已在我的托管服务提供商上起作用,所以不可能!


阅读 479

收藏
2020-05-17

共1个答案

一尘不染

该查询失败并返回false

将其放在后面mysqli_query()以查看发生了什么。

if (!$check1_res) {
    printf("Error: %s\n", mysqli_error($con));
    exit();
}

欲获得更多信息:

http://www.php.net/manual/zh/mysqli.error.php

2020-05-17