I'm trying to create a search bar for a website that Queries a PostgreSQL database, and the search function is not working. I don't get any errors and if I manually enter the query it works, but not if it uses the search term. Here is the relevant code.
$output = '';
if(isset($_POST['search']) && !empty($_POST['search'])){
$searchq=$_POST['search'];
$searchq=preg_replace("#[^0-9a-z]#i","",$searchq);
//$query= pg_query($conn,"SELECT * FROM restaurant WHERE name='Eataly'");
$query= pg_query($conn,"SELECT * FROM restaurant WHERE name = '%$searchq%'");
$count= pg_num_rows($query);
if($count==0){
$output = "There were no results";
}
else{
while ($row=pg_fetch_row($query)){
$fname= $row[0];
$output .="Restaurant: $row[1]";
}
}
}
The commented out query will run properly and display the correct data, however when I comment that line out and use the searchq variable instead it says that there are no results. Here is the relevant HTML as well.
<form action= "index.php" method = "post">
<input type"text" name = "search" placeholder= "Search"/>
<input type = "submit" value=">>"/>
Is there something I'm missing? I'm new to PHP so I'm not sure. Thanks.