我知道SQL注入,这只是测试代码。 我正在通过网址传递“用户”和“发布”的值,以使数据库中的某些内容出现在网站上。我收到此错误。
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given
...对于这一行代码...
while ($userrow = mysqli_fetch_assoc($userresult)) {
我正在使用结果变量,不知道为什么它不起作用。
这是我的其余代码
function getPost($conn) {
$userName = $_GET["user"];
$postid = $_GET["post"];
$usersql = "SELECT * FROM users WHERE userName = $userName";
$userresult = mysqli_query($conn, $usersql);
while ($userrow = mysqli_fetch_assoc($userresult)) {
$hostid = $userrow['userid'];
$sql = "SELECT * FROM posts WHERE hostid = '$hostid' AND postid = '$postid'";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
if (mysqli_num_rows($result)==0) {
echo '
<p>Error. Post does not exist.</p>
';
}
else {
$title = $row['title'];
$description = $row['description'];
$filename = "posts/".$hostid."/".$postid."*";
$fileinfo = glob($filename);
$fileext = explode(".", $fileinfo[0]);
$fileactualext = $fileext[1];
echo '
<div class="PostPage"><p>
'.$row['title'].'<br>
<img src="posts/'.$hostid.'/'.$postid.'>
'.$row['date'].'<br>
'.$row['description'].'<br>
</p>
</div>
';
}
}
}
}