/    Sign up×
Community /Pin to ProfileBookmark

Username validation using javascript and php/mysql!! Urgent

I need a validation code that would
1. grab the username from a field. (hopefully a script that does this action as soon as the field box is no longer active such when the user clicks somewhere else or ‘tab’ into another field box.)
2. look for the same username in mysql
3. if found, echo “username exist”. else { echo “username available”}
4. both “username exist” and “username avaible” should appear next to the input field.

This is for a new website i’m building that i hope to include user registeration in.
Thx for your help

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyJan 19.2009 — This isn't the place to request custom jobs to be done for free -- in fact, I don't know of any place you can go to request custom jobs to be done for free. As for this site, it is for helping you to develop your own code. So, show some code and I'm sure somebody will help you with any problems you're having with the code.
Copy linkTweet thisAlerts:
@WebnerdJan 19.2009 — Look into jQuery Ajax
Copy linkTweet thisAlerts:
@dota_phdauthorJan 19.2009 — I need a validation code that would

1. grab the username from a field. (hopefully a script that does this action as soon as the field box is no longer active such when the user clicks somewhere else or 'tab' into another field box.)

2. look for the same username in mysql

3. if found, echo "username exist". else { echo "username available"}

4. both "username exist" and "username avaible" should appear next to the input field.

This is for a new website i'm building that i hope to include user registeration in.

Thx for your help[/QUOTE]


I've already made a script to accomplish this. However, it wasn't cross compatible and some other stuff screws up.

I guess you're right. This is't the right place.

I've just been working on this script for the past 3 days and had no luck.
Copy linkTweet thisAlerts:
@MrNobodyJan 19.2009 — Post the script and point out what doesn't work and why. Someone will be glad to help.
Copy linkTweet thisAlerts:
@dota_phdauthorJan 25.2009 — <script type="text/javascript">

function toggle_username(userid) {

if (window.XMLHttpRequest) {

http = new XMLHttpRequest();

} else if (window.ActiveXObject) {

http = new ActiveXObject("Microsoft.XMLHTTP");

}

handle = document.getElementById(userid);

var url = 'visitor_includes/javascripts/confirm_username.php?';

if(handle.value.length > 0) {

var fullurl = url + 'do=check_username_exists&username=' + encodeURIComponent(handle.value);

http.open("GET", fullurl, true);

http.send(null);

http.onreadystatechange = statechange_username;

}else{

document.getElementById('username_exists').innerHTML = '';

}

}

function statechange_username() {

if (http.readyState == 4) {

var xmlObj = http.responseXML;

var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data;

document.getElementById('username_exists').innerHTML = html;

}

}

</script>



this is confirm_username.php:

<?php require_once("../../core_includes/connection.php"); ?>

<?php

$do = $_GET['do'];

switch($do) {

case 'check_username_exists':

if(get_magic_quotes_gpc()) {

$username = $_
GET['username'];

}else{

$username = addslashes($_GET['username']);

}

$count = mysql_num_rows(mysql_query("SELECT * FROM visitor_users WHERE username='".$username."'")); // must be configured correctl!!!

header('Content-Type: text/xml');

header('Pragma: no-cache');

echo '<?xml version="1.0" encoding="UTF-8"?>';

echo '<result>';

if($count > 0) {

echo 'That username already exists, please select another one.';

}else{

echo 'That username is available.';

}

echo '</result>';

break;

default:

echo 'Error, invalid action';

break;

}

?>

During test runs, i noticed this code is not cross compatible. Also, the script stops working as soon as a valid username is typed. So when i type a invalid username (a username already exist in mysql), it still say "that username is available".
Copy linkTweet thisAlerts:
@MrNobodyJan 25.2009 — First, change this:
[CODE]http.open("GET", fullurl, true);
http.send(null);
http.onreadystatechange = statechange_username;[/CODE]

to this:
[CODE]http.open("GET", fullurl, true);
http.onreadystatechange = statechange_username;
http.send(null);[/CODE]

Then, perhaps instead of this:
[CODE]var xmlObj = http.responseXML;[/CODE]
you should be working with this:
[CODE]var xmlObj = http.responseXML.documentElement;[/CODE]
I'm not that big of an expert on XML, though. ?
×

Success!

Help @dota_phd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...