I am trying to create a search field in PHP
and HTML
. My code is not showing any error message, however it doesn’t echo anything. My search page comes up blank.
Here is my PHP code:
<?php require './includes/databaseHandler.php'; if(isset($_POST['submit-search'])){ $search = mysqli_real_escape_string($con, $_POST['search']); $location = mysqli_real_escape_string($con, $_POST['location']); $sql = "SELECT * FROM business WHERE BusinessName LIKE '%$search%' OR Address LIKE '%$search%'"; $result = mysqli_query($con, $sql); $QueryResult = mysqli_num_rows($result); if($QueryResult > 0){ while ($row = mysqli_fetch_assoc($result)){ $url = $row['BusinessName']."<br/>"; echo "<a href='Businesspage.php?id={$row['id']}'>" . $url . "</a>"; echo $row['Address']."<br/>"; echo $row['Phone']."<br/> <hr>"; } }else{ echo "There are no result matching your search"; } } ?>
And my HTML code from the search form:
<form action="searchindex.php" method="POST"> <input id="form-control" class="form-control" type="text" placeholder="What are you looking for?" name="search"><i id="form-control" class="fa fa-map-marker" aria-hidden="true"></i> <input id="form-control" class="form-control" type="text" placeholder="Jabi, Abuja?" name="location"> <button class="btn btn-default" type="submit-search"><i class="fa fa-search"></i></button> </form>
Advertisement
Answer
This is wrong:
<button class="btn btn-default" type="submit-search">
It needs to be:
<button class="btn btn-default" type="submit" name="submit-search">