我收到错误消息:
Object of class mysqli_result could not be converted to string
这是我的代码:
$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>";
mysqli_query()
$result
您需要将其循环,然后访问记录。您只是不能直接将其用作$result变量。
while ($row = $result->fetch_assoc()) { echo $row['classtype']."<br>"; }