Jerzxu Posted June 27, 2007 Share Posted June 27, 2007 Okay basically I want AJAX and PHP to communicate together to real time update things. The problem is that it updates, but if I type in the user name I want to register (I have one put in the database) it doesn't change the text to: "User name unavailable" Below are my codes: <p><b>Email</b><br /> <input type="text" onkeyup="showEmail(this.value)" name="email" align="absmiddle"/><span id="txtemail"></span> <br /> That is the email form text box // JavaScript Document var xmlHttp function showEmail(str) { if (str.length==0) { document.getElementById("txtemail").innerHTML=" No Email Entered" return } xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="email.php" url=url+"?q="+str url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("txtemail").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; } the javascript code <?php $dbh=mysql_connect ("localhost", "**********", "******") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("********"); $q=$_REQUEST["q"]; $result=""; if (strlen($q) > 0) { $result = mysql_query("SELECT * FROM emails"); { if ($q != $result) { $response=" Email is Avaible"; } else { $response=" Email is Already Regristered"; } } } echo $response; ?> the PHP code. The database has one user added into it but when typed it doesn't change the text to: Email is Already Regristered. Link to comment https://forums.phpfreaks.com/topic/57368-problem-with-email-checker-which-is-powered-by-ajax-php-and-mysql/ Share on other sites More sharing options...
sayedsohail Posted July 11, 2007 Share Posted July 11, 2007 I noticed a small problem in your sql statement. Here is the workaround.. $result = mysql_query("SELECT * FROM emails where emailid = '$q'"); $test_rows = mysql_num_rows($result); if ($test_rows == 1){ echo " email already exists "; } else { echo "Email is available.";} } best of luck... Link to comment https://forums.phpfreaks.com/topic/57368-problem-with-email-checker-which-is-powered-by-ajax-php-and-mysql/#findComment-295406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.