I want to create a form which allows the user to type in a search and have it pick up the right values from a database and display them, for some reason I can't get my query to work it just displays "could not search"
Here is my php code
<?php
include "connect.php";
$output = '';
if(isset($_POST['search'])) {
$search = $_POST['search'];
$search = preg_replace("#[^0-9a-z]i#","", $search);
$query = mysqli_query("SELECT * FROM house WHERE town LIKE '%$search%'") or die ("Could not search");
$count = mysqli_num_rows($query);
if($count == 0){
$output = "There was no search results!";
}else{
while ($row = mysqli_fetch_array($query)) {
$town = $row ['town'];
$street = $row ['street'];
$bedrooms = $row ['bedrooms'];
$bathroom = $row ['bathrooms'];
$output .='<div> '.$town.''.$street.''.$bedrooms.''.$bathrooms.'</div>';
}
}
}
?>
Here is my form
<form action ="home.php" method = "post">
<input name="search" type="text" size="30" placeholder="Belfast"/>
<input type="submit" value="Search"/>
</form>
<?php print ("$output");?>
'%$search%'with'%".$search."%'...echoyour querySELECT * FROM house WHERE town LIKE '%$search%'and try the query from phpmyadmin or mysql...