I have a script running on my site for member signup on my site my user profile pages are in the following format http://coupo.org/members/profile.php?u=Leika
The signup form is written in the following manor:
<div id="major">
<div class="panel" id="merchantIntro">
<div class="inner">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td height="0px">
<h1> Sign up Today And Start Saving!</h1>
<br>
</td>
</tr>
<tr><td height="0px">
</td></tr>
<tr>
<td style="color:#555555;font-size:14px;padding:0 5px 0 5px;background-repeat:repeat">
<form method="post" action="regAction.php" name="member" onsubmit="return validateForm()">
<tr><td height="8px" style="background-repeat:repeat"></td></tr>
<tr>
<td style="color:#555555;font-size:14px;padding:0 5px 0 5px;background-repeat:repeat">
UserName
</td>
</tr>
<tr>
<td style="color:#666666;font-size:13px;padding:0 5px 0 5px;background-repeat:repeat">
<script type="text/javascript">
//function to create ajax object
function pullAjax(){
var a;
try{
a=new XMLHttpRequest()
}
catch(b)
{
try
{
a=new ActiveXObject("Msxml2.XMLHTTP")
}catch(b)
{
try
{
a=new ActiveXObject("Microsoft.XMLHTTP")
}
catch(b)
{
alert("Your browser broke!");return false
}
}
}
return a;
}
function validate()
{
site_root = '';
var x = document.getElementById('ucode');
var msg = document.getElementById('msg');
user = x.value;
code = '';
message = '';
obj=pullAjax();
obj.onreadystatechange=function()
{
if(obj.readyState==4)
{
eval("result = "+obj.responseText);
code = result['code'];
message = result['result'];
if(code <=0)
{
x.style.border = "1px solid red";
msg.style.color = "red";
}
else
{
x.style.border = "1px solid #000";
msg.style.color = "green";
}
msg.innerHTML = message;
}
}
obj.open("GET",site_root+"validate.php?username="+user,true);
obj.send(null);
}
</script>
<style>
#ucode{border: 1px solid #000;}
</style>
<input type="text" id="ucode" name="ucode" value="" />
<input type="button" onclick="validate();" value="Check Availability" />
<div id="msg"></div>
The validation side is written like this:
<?php
$user = strip_tags(trim($_REQUEST['username']));
if(strlen($user) <= 0)
{
echo json_encode(array('code' => -1,
'result' => 'Invalid username, please try again.'
));
die;
}
// Query database to check if the username is available
$query = "Select * from users where codename = '$user' ";
// Execute the above query using your own script and if it return you the
// result (row) we should return negative, else a success message.
$available = true;
if($available)
{
echo json_encode(array('code' => 1,
'result' => "Success,username $user is still available"
));
die;
}
else
{
echo json_encode(array('code' => 0,
'result' => "Sorry but username $user is already taken."
));
die;
}
die;
?>
Now everytime I try to puch the button to check availability it returns true everytime. Can someone tell me where I went wrong.
BTW the username field in the MySQL DB is called codename.
Someone please help me I am drowning here 🙁
Thanks Ahead....