I am unable to see the results I asked for, it also randomly displays the posts I didn't intend to search. Help would be greatly appreciated.
This part of the code seems to work
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();
}
I may have done something wrong with the query
else {
$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);
This part of the code seems okay
if ($resultCheck > 0) { // output data of each row
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();
}
}