I followed a tutorial on how to make a search bar functional and I am not seeing what I'm doing wrong. I am trying to give users the option to search for products. The end result is everything is being out-putted as 'Array'. The correct amount of search results show up.
My search bar is on my index page.
<form class="searchbar" action="/searchresults" method="POST">
<input class="inputsearchbar" type="text"
name="search" size="50">
<input class="searchButton" type="submit" value="Search" name="submit">
</label>
</form>
I then have a page called searchresults.php where my results are outputted to. I'm pulling from my products table in my database.
I have this at the top of the file..
if(!isset($_POST['search'])) {
header("Location:index.php");
die($e->getMessage());
}
$con = mysqli_connect("localhost", "root", "", "bfb");
$search_sql = "SELECT * FROM products WHERE name LIKE '%" . $_POST['search'] . "%' OR description LIKE '%" . $_POST['search'] . "%'";
$search_query=mysqli_query($con, $search_sql);
if (mysqli_num_rows($search_query)!=0) {
$search_rs=mysqli_fetch_assoc($search_query);
}
?>
Followed by this in the body to output the results...
<h1>Search Results</h1>
<?php
if(mysqli_num_rows($search_query)!=0) {
do { ?>
<p><?php echo $search_rs=['name']; ?></p>
<p><?php echo $search_rs=['description']; ?></p>
<?php } while ($search_rs=mysqli_fetch_assoc($search_query));
} else {
echo"Sorry, no results were found. Please try again.";
}
?>
</div>
Why are all of my results displaying as 'Array' and how can I correct this?
take out the extraneous equal sign (=)
<?php echo $search_rs['name']; ?>