It's pretty straight forward, just break it down into these steps:
1) Accept a posted user name
ie:
Code:
<form method='post' action='validate_username.php' name='validate_username'>
<input type='text' name='username' id='username' value="" />
<input type='submit' value='Check Name' />
</form>
PHP Code:
<?php
$userName = $_POST['username'];
2. Hit the DB to see if that name is available.
PHP Code:
$userName = $_POST['username'];
$clean['username'] = mysql_real_escape_string($userName);
$sql = "SELECT 1 FROM users WHERE username = '{$clean['username']}'";
$get = mysql_query($sql) or die(mysql_error()); // remove the die() command after testing
if(mysql_num_rows($get) > 0)
{
// user is not available.
}
else
{
// user is available.
}
3. Add output for those 2 cases, if their name is available, if their name isn't.
and boom, you have a proof of concept.
Now as a developer your role is to take that proof of concept and apply it to whatever you need to do.
One note:
I'm using "SELECT 1 FROM" syntax because I don't actually want any data, I'm just trying to see if a row exists. This is the cheapest way to run live row check queries.
good luck :p