View Full Version : how to check email/user ID avalibilty???

04-01-2010, 11:42 AM
everybody... i hope u all ppl will be fine and enjoying.

i m new user here.. if i did any mistakes. i m sorry for that..

Dear i m making a user Registration form... in which i have added a button CHECK AVAILIBILTY
this button work is to chck in DATABASE that the user Input email address or ID is availble are not..???

i m also using php language within the javascript... but i m not getting, how to assign php variable variable value to javascript variable??? plz help me

i know the mysql query..

$query=mysql_num_rows(mysql_query("SELECT user_email FROM user_area WHERE user_email='email'"))

/*1st email will be taken from input txt field and then match with database. if $query is equal to 1 then its mean email/ID not available, if $query is equal to zero its mean not avalibl.


<script language='javascript'>
var email_chk="document.getElementById('email').value";

// plz tell me what i do here

<form action="register_act.php" method="POST" name="register">
E-Mail Address :
<input type='text' name='email' id="email" >
<input type='button' name='Check' onClick='EMAIL_AVALIBLE()' value='Check E-Mail Avalibility' >


04-01-2010, 12:11 PM
how to assign php variable variable value to javascript variable???

I presume you didn't mean 'variable variable', as I don't see any variable variables in your code, but do you mean that you want the email address that the user has typed into your input field to become the value of var email_chk?

If so, then your code should work.

What is returned when you add to the function...?

alert('email_chk = '+email_chk);

04-01-2010, 12:24 PM
dear i want this..

for example a user put the email (qazi@yahoo.com)

below the email address field i show the button (chek availbilty)

when user click at that button a javascript Function
will be called (CHECK_AVALIBLE) as i mention in my above Post..

so there i m not getting that how to match user input Email address with the database address by using javascript and php..

if the user email address match so its mean email already registerd...
a message will display.. email already regsterd....

if not match with the database email
a message will display.. email avalible....

plz tell me that how do this....

04-01-2010, 12:48 PM
Sorry, I misunderstood you before.

OK, try this:

function instantiateRequest() {
var ajaxRequest; // The variable that makes Ajax possible!
//Browser Support Code
try {
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
//alert("Your browser is Opera 8.0+, Firefox, or Safari");
} catch (e) {
// Internet Explorer Browsers
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Oops! You seem to be having browser trouble!");
return false;

return ajaxRequest;

function EMAIL_AVALIBLE() {
var email_chk="document.getElementById('email').value";


function check_email_avail(email) {
ajaxRequest = instantiateRequest();
ajaxRequest.onreadystatechange = function() {// Create a function that will receive data sent from the server
if (ajaxRequest.readyState == 4) {
var htmlResponse = ajaxRequest.responseText;
//Do stuff here with any output from the php.
//In your case, this'll be simply telling the user whether or not that address was available.



04-01-2010, 01:01 PM



should have been:

ajaxRequest.open("GET", PATH_TO_A_FILE_CONTAINING_MYSQL_REQUEST+'?email='+email, true);

Then the file with the MySQL query in needs:

if (!empty($_GET['email'])) {
$requestedEmail = $_GET['email'];

//now $requestedEmail contains the email to put in your MySQL query