I've just started learning about mySQL together with PHP(basics), and I am stuck for 2 days now with this error. I have HTML code :
<html> <head> <title>Title</title> </head> <body> <?php include 'pehape.php' ?> <span>Username:</span><?php echo $var ?> </body> </html>
I am just trying to get the name of an user from database using this code:
<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; $conn = new mysqli($servername, $username, $password, $dbname); $var = $conn->query("SELECT Name FROM users WHERE ID=0"); ?>
This is what I get as a result in web browser.
Username: Recoverable fatal error: Object of class mysqli_result could not be converted to string in /storage/ssd3/749/7441749/public_html/index.php on line 7
Now after the result that I am getting is Object but I don't know how to convert it to string using PHP. -Does anyone know how to fix this?To convert Object to string.
I have tried using print_r function and it didn't work out for me.I found very little information about this.Also, this is my database structure if you need it for some information( I guess that might have impact, don't know) : http://prntscr.com/l5xu9n