Fatal error: you cannot use an object of type mysqli_result

I am going to open my site when I noticed that one of my mods gives me this error:

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

I went to line 303, and here is what I found:

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

Here is 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 am not an expert in php coding, so a little help would be great before opening a website. Any help / suggestions?

Thank you very much!

+6
source share
1 answer

You cannot use an object of type mysqli_result as an array

Use mysqli_fetch_assoc or mysqli_fetch_array to get the result string as an associative array.

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

or

 $followingdata = $result->fetch_array(MYSQLI_ASSOC); 
+21
source

Source: https://habr.com/ru/post/944892/


All Articles