48

Facebook User_id がデータベースに既に存在するかどうかを確認するのに問題があります(存在しない場合は、ユーザーを新しいユーザーとして受け入れ、キャンバスアプリケーションをロードするだけです)。ホスティングサーバーで実行しましたが問題はありませんでしたが、ローカルホストでは次のエラーが表示されます。

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;
}

クエリが間違っていることに関係があると読んだことがありますが、ホスティングプロバイダーで機能しているので、そうではありません!

4

1 に答える 1

127

に指定されたクエリmysqli_query()は失敗し、 を返しfalseます。

これを後mysqli_query()に置いて、何が起こっているかを確認してください。

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

詳細については:

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

于 2013-03-15T18:52:06.610 に答える