SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : HTML and CSS :

Previous DiscussionNext Discussion
 Problem with check username and email available with ajax, php and jquery

Hi .__. thanks for that amazing piece of code, and the step by step tutorial. I used first for check the user name, but I also need it for the e-mail. I had to make an user_availability2 and change the id=”msgbox” to id=”msgbox2″ (also in the function) and it was working great (when an email or user name were already in the db, I disabled the send button) until I noticed that if one of those were available the button turn to able again. So I have two options make only one function and send both of the variables or make a codition to check if one of them isn’t available and disable the button.

I’m a beginner :$ so I know a little about logic and I have the idea, but i turns complicate when i have to translate it to code. Any idea is welcome =) thanks

Here’s the code

//HTML code






//CSS code
.messagebox{
position:absolute;
width:100px;
margin-left:30px;
border:1px solid #c93;
background:#ffc;
padding:3px;
}
.messageboxok{
position:absolute;
width:auto;
margin-left:30px;
border:1px solid #349534;
background:#C9FFCA;
padding:3px;
font-weight:bold;
color:#008000;
}
.messageboxerror{
position:absolute;
width:auto;
margin-left:30px;
border:1px solid #CC0000;
background:#F7CBCA;
padding:3px;
font-weight:bold;
color:#CC0000;
}


//The jQuery library is used,




//This is the first function
$(document).ready(function()
{
$(”#user”).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:$(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);

});
document.form1.button.disabled=true;

}
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);
});
document.form1.button.disabled=false;
}

});

});
});


//The second one for validate email
$(document).ready(function()
{
$(”#email”).blur(function()
{
//remove all the class add the messagebox classes and start fading
$(”#msgbox2″).removeClass().addClass(’messagebox’).text(’Checking…’).fadeIn(”slow”);
//check the username exists or not from ajax
$.post(”user_availability2.php”,{ email:$(this).val() } ,function(data)
{
if(data==’no’) //if username not avaiable
{
$(”#msgbox2″).fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html(’This E-mail Already exists’).addClass(’messageboxerror’).fadeTo(900,1);

});
document.form1.button.disabled=true;

}
else
{
$(”#msgbox2″).fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html(’E-mail available to register’).addClass(’messageboxok’).fadeTo(900,1);
});
document.form1.button.disabled=false;
}

});

});
});


//PHP code
//This is user_availability.php
//this varible contains the array of existing users
connect();
$query = “SELECT * FROM users WHERE user = ‘”.$_POST['user'].”‘”;
$result = mysql_query($query);

//checking weather user exists or not in $existing_users array
if (mysql_num_rows($result)>0)
{
//user name is not availble
echo “no”;
}
else
{
//user name is available
echo “yes”;
}
disconnect();

//This is user_availability2.php
//this varible contains the array of existing users
connect();
$query = “SELECT * FROM users WHERE email = ‘”.$_POST['email'].”‘”;
$result = mysql_query($query);

//checking weather user exists or not in $existing_users array
if (mysql_num_rows($result)>0)
{
//user name is not availble
echo “no”;
}
else
{
//user name is available
echo “yes”;
}
disconnect();

Started By lauretta.gs on Sep 16, 2009 at 9:42:48 AM
This message has been edited.

1 Response(s) | Reply

Earlier Replies | Replies 1 to 1 of 1 | Later Replies
on (# 1)


Earlier Replies | Replies 1 to 1 of 1 | Later Replies

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.