I am creating a search bar on my website so users can search for other users and it works but if I enter one username , all of the usernames show up. How can I only show the user I am looking for and if the user isn't registered give an else statement ?
search.php :
<?php
include("connect.php");
GLOBAL $usernam;
$output = '';
if(isset($_POST['Search'])) {
if (empty($_POST["searchbar"])) {
echo"You didn't enter anything . ";
} else {
$searchq = $_POST['Search'];
$searchq = preg_replace("#[^0-9a-z]#i", "",$searchq);
$query = mysqli_query($conn ,"SELECT * FROM users WHERE usernam LIKE '%$searchq%'") or die("Could not search");
$count = mysqli_num_rows($query);
if($count == 0){
echo "There was no search results . ";
} else {
while($row = mysqli_fetch_array($query)) {
$usernam = $row['usernam'];
$id = $row['id'];
$output .= '<div>' .$usernam. '</div>';
}
}
}
}
?>
<html>
<head>
<title>Interpage</title>
</head>
<body>
<?php print("$output"); ?>
</body>
</html>