/    Sign up×
Community /Pin to ProfileBookmark

Hello I was wondering if you could help me basically i’m trying to check if a user name is availble using ajax… I’ve set it all up but it doesn’t seem to be reading what I enter it always gives the results found as 0..

Here is my code…
This page is my sign up page (I’ve only included the username field..)

[code=php]
<?php
require_once (“veriflogin.php”);
$outputValue = $xResult;
?>
<script type=”text/javascript”>

document.getElementById(‘username’).innerHTML = outputValue;

function checkUser(username) {

if(outputValue = file(‘veriflogin.php?username=’+escape(username)))
alert (“username”);
{

if(outputValue == 1) {
//writediv(‘<span style=”color:#cc0000″><b>’+login+’ :</b> is already used !</span>’);
alert (“Username already exists !”);

}

if(outputValue== 0) {
//writediv(‘<span style=”color:#006600″><b>’+login+’ :</b> is Available !</span>’);
alert (“This username is available”);
}

}

}

function file(filename)

{

if(window.XMLHttpRequest) // FIREFOX

xhr_object = new XMLHttpRequest();

else if(window.ActiveXObject) // IE

xhr_object = new ActiveXObject(“Microsoft.XMLHTTP”);

else

return(false);

xhr_object.open(“GET”, filename, false);

xhr_object.send(null);

if(xhr_object.readyState == 4) return(xhr_object.responseText);

else return(false);

}

</script>

<?php
require_once (“veriflogin.php”);

?>[/code]
[code=html]
<td bgcolor=”#CCCCCC”>Desired Username </td>
<td bgcolor=”#CCCCCC”><label>
<input name=”username” type=”text” id=”username” size=”40″ onFocus=”highlightField(‘username’)” onBlur=”checkUser(‘username’)”/><?php echo “$outputValue”; ?>
</label></td>[/code]

This is my php page called veriflogin.php

[code=php]<?php
require_once (“connect.php”);

$result = mysql_query(“SELECT username FROM users WHERE username='”.$_GET[“username”].”‘”);
if(mysql_num_rows($result)>=1)
$xResult = “1”;
else
$xResult = “0”;

?>[/code]

Every time I type a username in it’s just returning the result as 0 and alerting the username is available.. So the script is working with each other but it is not reading the username I input…

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@cluefulFeb 16.2011 — [CODE]onBlur="checkUser('username')"[/CODE][/QUOTE]You're passing a literal string.

Use:[CODE]onBlur="checkUser( this.value )"[/CODE]

[CODE] if(outputValue = file('veriflogin.php?username='+escape(username)))
alert ("username");[/CODE]
[/QUOTE]
Since you pass no parameters in the request, presumably you're reading the entire file. Again you're passing a literal string to the alert(); [CODE]alert (outputValue);[/CODE] should show the returned file contents, but then you need a means of searching for the wanted name.
×

Success!

Help @locksheathsaint 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.24,
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,
)...