FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


username availability script





riyadh
Code:
//this varible contains the array of existing users
$existing_users=array('roshan','mike','jason');
//value got from the get metho
$user_name=$_POST['user_name'];
//checking weather user exists or not in $existing_users array
if (in_array($user_name, $existing_users))
{
 //user name is not availble is available
 echo “no”;
}
else
{
 //user name doesn’t exists
 echo “yes”;
}


in the code above, i want to make such that the script checks for the usernames in the database because as you can see, updating the file everyday with taken usernames is just absurd.this script uses the AJAX and the jQuery library.here's the code for the checking

Code:
$("#username").blur(function()
{
 //remove all the class add the messagebox classes and start fading
 $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
 //check the username exists or not from ajax
 $.post("user_availability.php",{ user_name:$(this).val() } ,function(data)
 {
  if(data=='no') //if username not avaiable
  {
   $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
   {
    //add message and change the class of the box and start fading
    $(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1);
   });
  }
  else
  {
   $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
   {
    //add message and change the class of the box and start fading
    $(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1);
   });
  }
 });
});
alalex
Two things:
1- You are asking for help on a php file, so post that in the appropriate forum cat...

and 2 of course i'll help you:
Code:
$user_name=$_POST['user_name'];
$sql = 'SELECT * FROM `table_containing_usernames` WHERE `username`LIKE \''.$user_name.'\'';
$result = mysql_query($sql);
if($result>0){
echo 'yes';
}else{
echo 'no';
}


(Remember first to connect and select a database!)
And you are done Wink
rvec
moved
Related topics
script backup database
problem with a php randomizer script
how can i make a php script for enter username and password?
Looking for easy FormMail Script
simple login script
looking for password gate script
script no longer working on server 2 ????
Need help making logout script
How can I secure my MySQL connection script and config files
passing input from a form to a script
How hard would it be to make this script
150 frih to make this SIMPLE script
PHP Username And Password Login Script, Using those to creat
Username Checker & Identity Aggregator
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.