i have three file index.php , vragis.js , process.php. in index.php there is two controls username and email i am validating those with the help of ajax and php.after entering some values in email textbox error show below it after entering values in name textbox nothing going......
index.php
<div id="sigup" style="width:400px; float:right; margin-top:30px; margin-right:100px">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td colspan="2"><div style=" background-color:#330000; font-size:18px">Sign Up</div>
<br /></td>
</tr>
<tr>
<td colspan="2"><div style=" background-color:#330000; font-size:25px">It's All Free For Every One.</div>
<br /></td>
</tr>
<tr>
<td width="37%"><div style="float:right">Name</div></td>
<td width="63%"><div>
<input type="text" name="username" value="" id="username" onkeyup="valid_un()" />
<br /><span id="valiuser"> </span>
</div></td>
</tr>
<tr>
<td width="37%"><div style="float:right">E-mail</div></td>
<td width="63%"><div>
<input type="text" name="em" id="em" onkeyup="valid_e()"/>
<br /><span id="valie"> </span>
</div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="login" id="login" value=" Sign UP " style="border:#CCC 1px solid" onclick="ajaxFunction()"/>
</div></td>
</tr>
</table>
</div>
function call_ajx()
{
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
return xmlHttp;
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
return xmlHttp;
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}
}
function valid_un()
{
var xhr_un = call_ajx();
xhr_un.onreadystatechange=function()
{
if(xhr_un.readyState==4)
{
document.getElementById('valiuser').innerHTML=xhr_un.responseText;
}
}
var un=document.fblogin.username.value;
var url="process.php?u="+un;
xhr_un.open("GET",url,true);
xhr_un.send(null);
}
function valid_e()
{
var xhr_e = call_ajx();
xhr_e.onreadystatechange=function()
{
if(xhr_e.readyState==4)
{
document.getElementById('valie').innerHTML=xhr_e.responseText;
}
}
var e=document.fblogin.em.value;
var url="process.php?e="+e;
xhr_e.open("GET",url,true);
xhr_e.send(null);
}
process.php
<?php
$un=$_GET['u'];
$email=$_GET['e'];
$username=trim($un);
$pattern = "/^[-A-Za-z]+$/";
//$num_un=strlen($un);
//$num_e=strlen($email);
if(isset($un))
{
if(!$username)
{
echo "Blank Field Not Allowed";
}
else if (!preg_match($pattern,$username))
{
echo "alphanumerics,dash,underscore not Allowed";
}
else if (strlen($username)<4)
{
echo "Must Be Above Four Charecters";
}
else if(isset($username))
{
function username_taken($username)
{
include("config.php");
global $conn;
$q="select * from user_register where name = '$username'";
$result=mysql_query($q);
//$nr=mysql_affected_rows();
//echo "funcion uner".$result;
if(!$result || (mysql_numrows($result) < 1)){
return 1; //Indicates username failure
}
else
{
return 2;
}
}
$result=username_taken($username);// checking with functiion that user already in database or not rohit sharma
echo $status;
if($result == 1){
echo "This Is Free";
}
else if($result == 2){
echo "This User Name, Not Available";
}
}
}
if(isset($email))
{
if(!$email)
{
echo "Blank Field Not54545 Allowed";
}
}
?>