# Php simple search

**URL:** <https://forum.kirupa.com/t/php-simple-search/257935>\
**Category:** programming\
**Created:** [April 18, 2008, 3:58pm UTC](https://forum.kirupa.com/t/php-simple-search/257935 "2008-04-18T15:58:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [April 18, 2008, 3:58pm UTC](https://forum.kirupa.com/t/php-simple-search/257935/1 "2008-04-18T15:58:34Z")

</div>

Hello,

I’m looking for a simple search function in php to check if a user name is already created.  
I created a table “member” with 2 rows : “id” and “name”.

I want to create a simple form that checks if a name is already taken or is free.

The form i have now is :

```auto
<form method="get" action="search.php">
<input name="searchinput" type="text" value="check" onclick="this.value=''" />
<input type="image" src="gfx/button.jpg">
</form>

```

The php search i have now is

```php
<?php
mysql_connect("localhost"," *****","******");
mysql_select_db("database");
$search = $_GET["searchinput"];
$search = mysql_real_escape_string($search);
$result = mysql_query("SELECT * FROM member WHERE (name LIKE '%" . $search . "%')");    
if($search == ""){
print "ENTER SOMETHING";
}else{
if(mysql_num_rows($result) > 0) {
while($r=mysql_fetch_array($result)) {
$name = $r["name"];
print "$name already taken";
}      
} else {
print "$name already taken";
}
}
?>

```

The only problem with the script above is that when someone searches for “ste” or “steven” he doesn’t make a difference and because it is to check if a user name is already taken this isn’t a good solution.
