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>\";
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...
while ($row = $result->fetch_assoc()) {
echo $row[\'classtype\'].\"<br>\";
}
Before using the $result
variable, you should use $row = mysql_fetch_array($result)
or mysqli_fetch_assoc()
functions.
Like this:
$row = mysql_fetch_array($result);
and use the $row
array as you need.
Try with:
$row = mysqli_fetch_assoc($result);
echo \"my result <a href=\'data/\" . $row[\'classtype\'] . \".php\'>My account</a>\";
Make sure that mysqli_connect()
is creating the connection to the DB. You can use mysqli_errno()
to check for errors.