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=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>
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”;
?>
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…