mysqli fetch array expects parameter 1 to be mysqli result boolean given in

0 votes

I am having an issue with the function where it checks if a Facebook user id is there in the database or not. It works in the hosting server but gives an error in the local host.

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

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

Can someone help me solve this issue?

Apr 30, 2022 in Other DevOps Questions by Kichu
• 19,040 points
1,666 views

1 answer to this question.

0 votes

The issue is that the query given to mysqli_query() is failing and returning false. 

To solve this just put this after mysqli_query() :

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

For more information: http://www.php.net/manual/en/mysqli.error.php.

answered May 1, 2022 by narikkadan
• 63,600 points

Related Questions In Other DevOps Questions

0 votes
1 answer

How to get issues count based on rules in a sonar project?

There are API docs in the footer ...READ MORE

answered May 4, 2018 in Other DevOps Questions by DareDev
• 6,890 points
2,847 views
+1 vote
2 answers

When do we use Chef or Azure SDK to create VM and deploy in automation

The solution to the automated deployment in ...READ MORE

answered Aug 21, 2018 in Other DevOps Questions by Priyaj
• 58,020 points
1,145 views
0 votes
1 answer

How to stop sqlplus command in unix shell script when any sql fails

One idea would be to launch the ...READ MORE

answered Jul 16, 2018 in Other DevOps Questions by Kalgi
• 52,350 points
5,183 views
0 votes
1 answer
0 votes
0 answers

How to retrieve data from multiple tables using a PHP form?

I want to retrieve data from multiple ...READ MORE

Jun 25, 2022 in PHP by narikkadan
• 63,600 points
1,965 views
0 votes
0 answers

How to delete image form folder and database

With the code below, I'm displaying data ...READ MORE

Jul 26, 2022 in PHP by Kithuzzz
• 38,000 points
1,340 views
0 votes
0 answers

PHP MySQLi num_rows Always Returns 0

In order to make database interaction simpler, ...READ MORE

Aug 7, 2022 in PHP by Kithuzzz
• 38,000 points
1,068 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP