gpt4 book ai didi

php - 显示数据库记录 MySQLI

转载 作者:行者123 更新时间:2023-11-29 00:18:08 25 4
gpt4 key购买 nike

我正在尝试显示我的数据库中的一条记录,但是该页面显示为空白并且没有显示我期望的数据。代码如下:

<?php 
$mysqli = new mysqli(localhost, root, USERPASS, DBNAME);
$query = "SELECT * FROM usertable WHERE userID= '" . $_SESSION["sess_uid"] . "'";
$result = mysqli_query($mysqli, $query);
$row = mysqli_fetch_row($result);

echo $row['userQuestion'];
?>

如有任何帮助,我们将不胜感激。

谢谢

最佳答案

<?php 
// there need to be strings arguments here
$mysqli = new mysqli('localhost', 'root', USERPASS, DBNAME);
// sql injection friendly query
$query = "SELECT * FROM `usertable`
WHERE `userID`='{$_SESSION["sess_uid"]}' LIMIT 1;";
// do we have a result
if($result = mysqli_query($mysqli, $query)){
// fetch a single row
if($row = mysqli_fetch_row($result)){
// print the record
var_dump($row);
}
}
?>

您需要将 'localhost''root' 包装为字符串。

关于php - 显示数据库记录 MySQLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22132518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com