This question already has an answer here:
I'm trying to create a search function on my website. I've been following a few videos etc on how to get it working but thus far the only reply I'm getting from my search bar is no results found. Could you guys take a look, to see where I have gone wrong. Thanks
$output = '';
if (isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysqli_query("SELECT * FROM loanusers WHERE username LIKE '%$searchq%' OR userid LIKE '%$searchq%'");
$count = mysqli_num_rows($query);
if ($count == 0) {
$output = 'No results found';
}else{
while($row = mysqli_fetch_array($query)){
$username = $row['username'];
$userid = $row['userid'];
$output .= '<div> '.$username.' '.$userid.' </div>';
}
}
}
<body>
<form action="allusers.php" method="post">
<input type="button" name="Create User" value="Create New User" onclick="window.location.href='adminadduser.php'">
<input type="text" name="search" placeholder="Search Users...">
<input type="submit" value=">>">
</form>
<?php print("$output");?>
</div>