I am getting the error:
Object of class mysqli_result could not be converted to string
This is my code:
$username2 = htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');
$con = mysqli_connect('localhost','root','','test');
$result = mysqli_query($con, "SELECT classtype FROM learn_users
WHERE username='$username2';");
echo "my result <a href='data/$result.php'>My account</a>";
Try with:
The
mysqli_query()
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.The code...
Make sure that
mysqli_connect()
is creating the connection to the DB. You can usemysqli_errno()
to check for errors.Before using the
$result
variable, you should use$row = mysql_fetch_array($result)
ormysqli_fetch_assoc()
functions.Like this:
and use the
$row
array as you need.