I am getting the error:
Object of class mysqli_result could not be converted to string
This is my code:
$result = mysqli_query($con, "SELECT classtype FROM learn_users WHERE username='abcde'"); echo "my result <a href='data/$result.php'>My account</a>";
The mysqli_result class ¶Represents the result set obtained from a query against the database.
Return Values ¶ For successful queries which produce a result set, such as SELECT, SHOW, DESCRIBE or EXPLAIN , mysqli_query() will return a mysqli_result object. For other successful queries, mysqli_query() will return true .
Example. <? php //Creating a connection $con = mysqli_connect("localhost", "root", "password", "mydb"); //Executing the multi query $query = "SELECT * FROM players"; //Retrieving the records $res = mysqli_query($con, $query, MYSQLI_USE_RESULT); if ($res) { while ($row = mysqli_fetch_row($res)) { print("Name: ".
The mysqli_query()
method returns an object resource to your $result
variable, not a string.
You need to loop it up and then access the records. You just can't directly use it as your $result
variable.
while ($row = $result->fetch_assoc()) { echo $row['classtype']."<br>"; }
Before using the $result
variable, you should use $row = mysqli_fetch_array($result)
or mysqli_fetch_assoc()
functions.
Like this:
$row = mysqli_fetch_array($result);
and use the $row
array as you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With