我无法看到我要求的结果,它也随机显示我没有打算搜索的帖子。非常感谢帮助。
这部分代码似乎有用
if (isset($_POST['submitSearch'])) {
include_once 'dbh.inc.php';
$search = mysqli_real_escape_string($conn, $_POST['searchEnter']);
$search = htmlspecialchars($search);
//$postcommentidGet = mysqli_real_escape_string($conn, $_GET['id']);
if (empty($search)) {
header("Location: ../search.php?search=empty");
exit();
}
我可能在查询中做错了什么
其他{
$username=$_SESSION['u_uid'];
$sql = "SELECT * FROM posts WHERE (posts_title LIKE '%".$search."%'') OR (posts_content LIKE '%".$search."%')";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
这部分代码似乎没问题
if($ resultCheck> 0){ //输出每行的数据
while($row = mysqli_fetch_assoc($result)) {
echo'
<div class="searchResults">
<p>'.$row['posts_title'].' '.$row['posts_content'].'</p><br>
</div>
';
}
}
//exit();
}
} else {
header("Location: ../signup.php");
exit();
}
}