Hello campers! <3
so i am new to coding, i wrote this code for making a search field and i keep having this problem can anyone help me
my code :
<?php include 'header.php'; ?>
<h1>Search Page</h1>
<div class="article-container">
<?php
if ($_POST['submit-search']){
$Search = mysqli_real_escape_string($conn,$_POST['search']);
$sql = "SELECT * articals WHERE a_title LIKE '%$search%' OR a_artical LIKE '%$search%'OR a_author LIKE '%$search%' a_date LIKE '%$search%' ";
$result = mysqli_query($conn,$sql);
$queryReslut = mysqli_num_rows($result);
if ($queryReslut > 0 ) {
while ($row = mysqli_fetch_assoc($reslut)) {
echo "<div>
<h3>".$row['a_title']."</h3>
<p>". $row['a_text']."</p>
<p>". $row['a_date']."</p>
<p>". $row['a_author']. "</p>
</div>";
}
} else if ($queryReslut = 0) {
echo "There are no results matching your search!";
}
}
?>
The error i get : Warning : mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\Program Files\Ampps\www\test\searchfield\index.php on line 15
Here’s the thing: there’s an error in your SQL statement, which is causing mysql_query() to fail. When it fails, it returns a Boolean false value, rather than the mysqli_result return value that mysql_num_rows() is looking for.
Either fix the SQL, or handle the error coming from your mysql_query() call.
it worked!
but i did not get the articals not in the index page or in the artical page where it shows after searching
i am new to all of this, it is a little bit hard but i am getting throw
Thank you so much!
The error in the SQL was just at the end, the last option wasn’t led by an OR. Once the SQL was fixed, it should work fine. Wouldn’t be a bad idea to error-check that though:
$result = mysqli_query($conn, $sql);
if ($result == false){
// Here, you have an error, handle it!
} else {
// Here, we KNOW that result isn't false, so it's safe!
$resultNRows = mysqlI_num_rows($result);
// ... and on and on.