Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Cannot use object of type mysqli_result [closed]

Tags:

arrays

php

mysqli

I'm about to open my website when I noticed that one of my mods gives me this error:

Fatal error: Cannot use object of type mysqli_result as array in /var/www/vbsubscribetouser.php on line 303

I've went to line 303 and this is what I found:

//Check if requested username can be followed.
if (in_array($followingdata['usergroupid'], explode("|", $vbulletin->options['subscribetouser_usergroups_cannot']))){

Here is all the code starting at line 303:

//Check if requested username can be followed.
if (in_array($followingdata['usergroupid'], explode("|", $vbulletin->options['subscribetouser_usergroups_cannot']))){
    exit;
}

if ($followinginfo[subscribers] > 0){
    $user_followers = $followinginfo[followers].$userinfo[userid].'|';
}
else{
    $user_followers = '|'.$userinfo[userid].'|';
}

$vbulletin->db->query_write("
    UPDATE " . TABLE_PREFIX . "user
    SET subscribers = subscribers + 1, `followers` = '$user_followers'
    WHERE userid = $followinginfo[userid]
");

I'm not an expert in php coding, so a bit of help would be great before opening the website. Any help/suggestions?

Thank you very much!

like image 954
Sergio Mironescu Iancu Avatar asked May 13 '13 15:05

Sergio Mironescu Iancu


1 Answers

Cannot use object of type mysqli_result as array

Use mysqli_fetch_assoc or mysqli_fetch_array to fetch a result row as an associative array.

$query = "SELECT 1";
$result = $mysqli->query($query);
$followingdata = $result->fetch_assoc()

or

$followingdata = $result->fetch_array(MYSQLI_ASSOC);
like image 53
Kermit Avatar answered Nov 09 '22 00:11

Kermit