I’ve to be trying to update this manuscript with no luck. I’m obtaining the adhering to error.

You are watching: Cannot use object of type stdclass as array

PHP deadly error: Uncaught Error: Cannot use object of form stdClass as variety on heat 17:

";} #index.php of our rootinclude_once "file-uploading/dbconfig.php";$sql = "SELECT * native `facebook` stimulate by rand() limit 1";$result = mysqli_query($link, $sql);while($row = mysqli_fetch_object($result)) $topic = htmlentities($row<"topic">); $name = htmlentities($row<"name">); $file = htmlentities($row<"file">); $description = htmlentities($row<"description">);Anyone understand what’s wrong?

Thank you


*
Freejoy:

mysqli_fetch_object($result)

The result set you are getting back from the questions is an object, however you room trying come use range notation as soon as you assign the values to variables - e.g. $name = htmlentities($row<"name">);.


Note the htmlentities() is unnecessary if you working with UTF-8 consequently! the only function that is crucial is htmlspecialchars().

See more: Gru Despicable Me Accent S And Subtle Departures, Felonius Gru

additionally, calculation escaping have to be left come your output rendering engine. And even if you usage PHP for that, array functions make that easier.


I done it this way:

while($row = mysqli_fetch_object($result)) $topic = htmlentities(<"topic">); $name = htmlentities(<"name">); $file = htmlentities(<"file">); $description = htmlentities(<"description">);It works however the photo doesn’t post and also I gain the following errors:

<18-Jan-2017 18:36:01 UTC> PHP Warning: htmlentities() expects parameter 1 to be string, selection given in /home/path/public_html/facebook/index.php on line 17<18-Jan-2017 18:36:01 UTC> PHP Warning: htmlentities() expects parameter 1 to it is in string, selection given in /home/path/public_html/facebook/index.php on heat 18<18-Jan-2017 18:36:01 UTC> PHP Warning: htmlentities() expects parameter 1 to be string, array given in /home/path/public_html/facebook/index.php on heat 19<18-Jan-2017 18:36:01 UTC> PHP Warning: htmlentities() expects parameter 1 to be string, selection given in /home/path/public_html/facebook/index.php on line 20<18-Jan-2017 18:36:02 UTC> PHP Catchable fatal error: thing of course mysqli_result can not be converted to wire in /home/path/public_html/facebook/index.php on heat 81The error on heat 81 is: $html .= $result;:

} rather { $html = ""; $html .= ""; $html .= ""; $html .= ""; $html .= $result; $html .= "