lee2010 Posted January 27, 2011 Share Posted January 27, 2011 Hi all, i have a script which checks the username field of my register form as the user types it and checks to see if the username is either taken, is too short or availible using jquery, however it isn't working and i've been staring at it for ages trying to work out why. Due to the length of my code ive put it on codepad. Here is my register.php: http://codepad.org/8REOfI8q and here is my check.php: http://codepad.org/gXSkbnsf My form is just displaying "Choose a username" and not changing depending on my input etc... Any help would be great Quote Link to comment https://forums.phpfreaks.com/topic/225845-dynamic-username-check/ Share on other sites More sharing options...
andrew_biggart Posted January 27, 2011 Share Posted January 27, 2011 Can you post your code on here? Its easier to read that way. Also have a look at this post http://www.phpfreaks.com/forums/php-coding-help/adding-a-count-and-while-loop-using-xml-data/ of my mine and see if you can solve my issue while I try and solve yours. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/225845-dynamic-username-check/#findComment-1165948 Share on other sites More sharing options...
lee2010 Posted January 27, 2011 Author Share Posted January 27, 2011 sure, here we go check.php: <?php mysql_connect("localhost", "lee", "leecopter"); mysql_select_db("lee"); $username = mysql_real_escape_string($_POST['username']); $check = mysql_query("SELECT username FROM users WHERE username='$username'"); $check_num_rows = mysql_num_rows($check); if ($username==NULL) echo "Choose a username"; else if (strlen($username)<=3) echo "Username is too short"; else { if ($check_num_rows==0) echo "Username is availible!"; else if ($check_num_rows==1) echo "Username has already been taken"; } ?> register.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!-- Author: Reality Software Website: http://www.realitysoftware.ca Note: This is a free template released under the Creative Commons Attribution 3.0 license, which means you can use it in any way you want provided you keep the link to the author intact. --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#feedback').load('check.php').show(); $('#username_input').keyup(function(){ $.post('check.php', { username: register.username.value}, function(result) { $('#feedback').html(result).show(); }); }); }); </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link href="style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> .auto-style2 { font-size: 25px; } .auto-style3 { font-size: small; } </style> </head> <body> <div id="container"> <!-- header --> <div id="header"> <div id="logo"><a href="#"><span class="orange">SouthWest</span> LAN's</a></div> <div id="menu"> <ul> <li><a href="index.php">Home</a></li> <li><a href="events.php">Events</a></li> <li><a href="account.php">My Account</a></li> <li><a href="forum.php">Forums</a></li> <li><a href="faq.php">FAQ</a></li> </ul> </div> </div> <!--end header --> <!-- main --> <div id="main"> <div id="content"> <div id="head_image"> <div id="slogan"><strong><span class="auto-style2">Organising LAN Parties in the SouthWest</span></strong><br /></div> <div id="under_slogan_text"></div> </div> <div id="text"> <h1>Registration:</h1> <br /> <p class="auto-style3">Don't forget your login details as you will need them everytime you wish to login.</p> <form name="register" method="post" action="process_r.php"> <table border="0" width="225" align="center"> <tr> <td width="219" bgcolor="#999999"> <p align="center"><font color="white"><span style="font-size:12pt;"> All fields are required</span></font></p> </td> </tr> <tr> <td width="219"> <table border="0" width="282" align="center"> <tr> <td width="116"><span style="font-size:10pt;">Username:</span></td> <td width="156"><input type="text" id="username_input" name="username" maxlength="100"></td> </tr> <tr> <td width="116"><span style="font-size:10pt;"></span></td> <td width="116"><div id="feedback"></div></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Email:</span></td> <td width="156"><input type="text" name="email" maxlength="100"></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Password</span></td> <td width="156"><input type="password" name="password"></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Confirm Password:</span></td> <td width="156"><input type="password" name="c_password"></td> </tr> <tr> <td width="116"> </td> <td width="156"> <p align="right"><input type="submit" name="register" value="Register"></p> </td> </tr> </table> </td> </tr> </table> </form> </div> </div> </div> </div> <!-- end main --> <!-- footer --> <div id="footer"> <div id="left_footer"><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a><br />© Copyright 2008 Clicker design </div> <div id="right_footer"> <!-- Please do not change or delete this link. Read the license! Thanks. :-) --> Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality Software</a> </div> </div> <!-- end footer --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/225845-dynamic-username-check/#findComment-1165950 Share on other sites More sharing options...
andrew_biggart Posted January 27, 2011 Share Posted January 27, 2011 Try this <?php mysql_connect("localhost", "lee", "leecopter"); mysql_select_db("lee"); $username = mysql_real_escape_string($_POST['username']); $check = mysql_query("SELECT username FROM users WHERE username='$username'"); $check_num_rows = mysql_num_rows($check); if ($username=="") echo "Choose a username"; else if (strlen($username)<=3) echo "Username is too short"; else { if ($check_num_rows==0) echo "Username is availible!"; else if ($check_num_rows==1) echo "Username has already been taken"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225845-dynamic-username-check/#findComment-1165964 Share on other sites More sharing options...
lee2010 Posted January 27, 2011 Author Share Posted January 27, 2011 still no difference im afraid Quote Link to comment https://forums.phpfreaks.com/topic/225845-dynamic-username-check/#findComment-1165966 Share on other sites More sharing options...
andrew_biggart Posted January 27, 2011 Share Posted January 27, 2011 What about this? <?php mysql_connect("localhost", "lee", "leecopter"); mysql_select_db("lee"); $username = mysql_real_escape_string($_POST['username']); $check = mysql_query("SELECT username FROM users WHERE username='$username'"); $check_num_rows = mysql_num_rows($check); if (strlen($username)<=1) echo "Choose a username"; else if (strlen($username)<=3) echo "Username is too short"; else { if ($check_num_rows==0) echo "Username is availible!"; else if ($check_num_rows==1) echo "Username has already been taken"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225845-dynamic-username-check/#findComment-1165970 Share on other sites More sharing options...
andrew_biggart Posted January 27, 2011 Share Posted January 27, 2011 If it did please click Solved! Quote Link to comment https://forums.phpfreaks.com/topic/225845-dynamic-username-check/#findComment-1165978 Share on other sites More sharing options...
lee2010 Posted January 27, 2011 Author Share Posted January 27, 2011 nope afraid not, i dont even think the problem is with the check.php, i think the problem is in the script or form on the register.php page Quote Link to comment https://forums.phpfreaks.com/topic/225845-dynamic-username-check/#findComment-1165987 Share on other sites More sharing options...
PFMaBiSmAd Posted January 27, 2011 Share Posted January 27, 2011 The following will (tested) send the field data to your check.php file and display the response that is sent back - $(document).ready(function(){ $("#username_input").keyup(function(){ txt=$("#username_input").val(); $.post("check.php",{username:txt},function(result){ $("#feedback").html(result); }); }); }); Quote Link to comment https://forums.phpfreaks.com/topic/225845-dynamic-username-check/#findComment-1165998 Share on other sites More sharing options...
lee2010 Posted January 27, 2011 Author Share Posted January 27, 2011 perfect, thanks very much! Quote Link to comment https://forums.phpfreaks.com/topic/225845-dynamic-username-check/#findComment-1166041 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.