Home >Backend Development >PHP Tutorial >How to Fix the 'Object of class mysqli_result could not be converted to string' Error in PHP?
The error "Object of class mysqli_result could not be converted to string" occurs when trying to use a mysqli_result object as a string.
Problem:
You have encountered the error in your code, particularly in the following line:
echo "my result <a href='data/$result.php'>My account</a>";
In this line, you are attempting to use the $result variable, which is an object of class mysqli_result, as a string.
Solution:
The issue is that the mysqli_query() method returns an object resource to the $result variable, not a string. To access the result of the query, you need to loop through the rows of the result set and retrieve the values for each row.
while ($row = $result->fetch_assoc()) { echo $row['classtype'] . "<br>"; }
By using the fetch_assoc() method, you can iterate through the result set and access the value of the classtype column for each row.
The above is the detailed content of How to Fix the 'Object of class mysqli_result could not be converted to string' Error in PHP?. For more information, please follow other related articles on the PHP Chinese website!