By Mats de Swart


2013-03-15 18:43:11 8 Comments

I'm have some trouble checking if a Facebook User_id already exists in my database (if it doesn't it should then accept the user as a new one and else just load the canvas application). I ran it on my hosting server and there was no problem, but on my localhost it gives me the following error:

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

Here's my code:

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

I've read it has something to do with my query being wrong, but it has worked on my hosting provider so that can't be it!

1 comments

@castis 2013-03-15 18:52:06

That query is failing and returning false.

Put this after mysqli_query() to see what's going on.

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

For more information:

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

Related Questions

Sponsored Content

21 Answered Questions

[SOLVED] How can I declare and use Boolean variables in a shell script?

15 Answered Questions

[SOLVED] Parsing boolean values with argparse

30 Answered Questions

[SOLVED] Converting from a string to boolean in Python?

  • 2009-04-03 19:44:20
  • Joan Venge
  • 545575 View
  • 649 Score
  • 30 Answer
  • Tags:   python string boolean

16 Answered Questions

[SOLVED] Using boolean values in C

  • 2009-12-17 12:46:49
  • neuromancer
  • 1261622 View
  • 657 Score
  • 16 Answer
  • Tags:   c boolean

12 Answered Questions

[SOLVED] Which MySQL data type to use for storing boolean values

32 Answered Questions

63 Answered Questions

[SOLVED] Check if at least two out of three booleans are true

2 Answered Questions

[SOLVED] Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, array given

  • 2015-04-28 06:44:58
  • jckhan
  • 600 View
  • 1 Score
  • 2 Answer
  • Tags:   php

3 Answered Questions

Sponsored Content