I am trying to put together a search bar for my database using php, and I have encountered this problem, even though all of my brackets are closed. This is my form page:
<?php
require_once('connect.php');
?>
<html>
<head>
</head>
<body>
<form action="search.php" method="post">
<label>
Search
<input type="text" name="search" placeholder="Search for members" autocomplete="off">
</label>
<input type="submit" value=">>" />
</form>
</body>
</html>
And this is my php code for search.php
<?php
require_once('connect.php');
$output = '';
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^a-z]#i", "", $searchq);
$query = mysql_query("SELECT * FROM newclient WHERE first_name LIKE '%$searchq%' OR last_name LIKE '%$searchq%'") or die("Could not search!");
$count = mysql_num_rows($query) ;
if ($count == 0) {
$output = "There was no search result!";
}
else{
while ($row = mysql_fetch_array($query)){
$fname = $row['firstname'];
$lname = $row['lastname'];
$id = $row['id'];
$output .= '<div>'.$fname.' '.$lname.'</div>';
}
}
print("$output");
?>