bindiya Posted December 15, 2010 Share Posted December 15, 2010 I am writing a code using jquery in a php page to check the username availabiltiy,but getting error ie every time username is available is the message i am getting. the code is $(document).ready(function() { $("#username").blur(function() { //remove all the class add the messagebox classes and start fading $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow"); //check the username exists or not from ajax //$.post("themes/user_availability.php",{ username:$(this).val() } ,function(data) $.post("themes/user_availability.php",{username:$(this).val() } ,function(data) { if(data=="no") //if username not avaiable { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1); }); } if(data=="yes") { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1); }); } }); }); }); php file user_availability.php <?php $login=$_POST['username']; $sql="select username from web_payregister where username='$login'"; $result=mysql_query($sql); if(mysql_num_rows($result)>0){ echo "no"; }else{ echo "yes"; } ?> Link to comment https://forums.phpfreaks.com/topic/221736-getting-error-in-this-useravailability-check-code/ Share on other sites More sharing options...
solon Posted December 15, 2010 Share Posted December 15, 2010 Hello bindiya... Can you post the exact error you get? Also, is the error displayed in the html where it supposed to return the 'available' or 'not available' ? Link to comment https://forums.phpfreaks.com/topic/221736-getting-error-in-this-useravailability-check-code/#findComment-1147571 Share on other sites More sharing options...
bindiya Posted December 15, 2010 Author Share Posted December 15, 2010 i check the username with database content.So if the username is available or not available i get the message on the left side of the inputbox "Username is available to register". Link to comment https://forums.phpfreaks.com/topic/221736-getting-error-in-this-useravailability-check-code/#findComment-1147572 Share on other sites More sharing options...
solon Posted December 15, 2010 Share Posted December 15, 2010 OK... try the following and post the result you get... change your php code to this and run it once to see what it returns... $login=$_POST['username']; echo $login; /* $sql="select username from web_payregister where username='$login'"; $result=mysql_query($sql); if(mysql_num_rows($result)>0){ echo "no"; }else{ echo "yes"; }*/ Sorry try this ... the one before what give you another kind of error and post it here so we can see where the problem is! Link to comment https://forums.phpfreaks.com/topic/221736-getting-error-in-this-useravailability-check-code/#findComment-1147575 Share on other sites More sharing options...
bindiya Posted December 15, 2010 Author Share Posted December 15, 2010 notthing is echoed.!!!!!!!!! Link to comment https://forums.phpfreaks.com/topic/221736-getting-error-in-this-useravailability-check-code/#findComment-1147582 Share on other sites More sharing options...
solon Posted December 15, 2010 Share Posted December 15, 2010 That means that your ajax function is either not passing the variable correctly to the php script or the ajax funcion does not get the value from your form... Can you please also post the code for your form? Link to comment https://forums.phpfreaks.com/topic/221736-getting-error-in-this-useravailability-check-code/#findComment-1147584 Share on other sites More sharing options...
bindiya Posted December 15, 2010 Author Share Posted December 15, 2010 <form name='registration' action='' method='post' onsubmit="return verify();"> <table width="599" align='center'> <tr><td colspan='5'></td></tr> <tr><td width="33"></td> <td width="187"> User Name <font color="#CC0000">*</font></sup> </td> <td width="22">:</td> <td width="148"> <div> <input name="username" type="text" id="username" value="" maxlength="15" /><span id="msgbox" style="display:none"></span></div></td><td width="185"></td> </tr> <tr><td width="33"></td> <td width="187">Password<sup><font color="#CC0000">*</font></sup></td> <td width="22">:</td> <td width="148"><input name="password" type='text' /></td><td></td></tr> </table></form> Link to comment https://forums.phpfreaks.com/topic/221736-getting-error-in-this-useravailability-check-code/#findComment-1147585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.