View Single Post
Old 07-27-2009, 04:25 AM   #15 (permalink)
dschreck
The Contributor
 
dschreck's Avatar
 
Join Date: Nov 2007
Location: California
Posts: 82
Thanks: 0
dschreck is on a distinguished road
Default

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
__________________
Where I Ramble: http://www.iwilldomybest.com/
What I do: Zynga Game Network
Senior Software Engineer at CityVille
dschreck is offline  
Reply With Quote