Creating a php search bar

I want to put a search box so that when you type in a persons name it selects that persons details from the database.

This is my search box:


<form action="users.php" method="GET">
<input id="search" type="text" placeholder="Type here">
<input id="submit" type="submit" value="Search">

Then here is my PHP to return the users:


$connection = mysql_connect("localhost","root","");

mysql_select_db("blog1")or die(mysql_error());

$result = mysql_query("SELECT username FROM member");
 while ($row = mysql_fetch_assoc($result)) {
echo "<div id='link' onClick='addText(\"".$row['username']."\");'>" . $row['username'] . "</div>";  


How to get it to just return the user that i type in the search bar instead of all the users? Any help would be great as I am just learning PHP.

Leave a Comment