Evilzebra Posted October 17, 2007 Share Posted October 17, 2007 On the form page I have <script language="javascript" type="text/javascript"> var xmlHttp function showUser(str) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="check.php" url=url+"?check_user="+str xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("displayConfirm").innerHTML=xmlHttp.responseText } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { //Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } </script> <H1 align="center">Login</H1> <form name="form1" method="post" action="index.php?p=login"> <p align="center"> <b>Username:</b><br><input name="username" type="text" id="username" onblur="showUser(this.value);"><div id="displayConfirm"></div> <p align="center"> <b>Password:</b><br><input name="password" type="password" id="password"><br> <a href="index.php?p=forgot">Forgot your password?</a><br><br> <input type="checkbox" name="keep" id="keep">Keep me logged in.<a href="#" onmouseover="Tip('Checking this box will keep you logged in for 30 days.')">[?]</a><br><br> <input class="button" onClick="ajaxFunction();" value="Login" type="button"> </p> </form> And a separate file(check.php) I have <? $loginUsername = $_GET['check_user']; $query = "SELECT * FROM users WHERE Name='$loginUsername'"; $result = mysql_query($query); if($result && mysql_num_rows($result) == 1){ Echo "Username found"; } else { Echo $loginUsername; } ?> When I test out the code it will dynamically print the username as you type it in but it won't seem to find the username in the database. I am using Firefox. I have triple check my DB and it that is all correct. Quote Link to comment Share on other sites More sharing options...
rochakchauhan Posted October 19, 2007 Share Posted October 19, 2007 Try this.. check.php <?php $loginUsername = $_GET['check_user']; $query = "SELECT * FROM users WHERE Name='$loginUsername'"; $result = mysql_query($query); if(mysql_num_rows($result)>0){ echo "Sorry: $loginUsername is unavailable"; } else { echo "Congrats $loginUsername is available"; } ?> Quote Link to comment 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.