Jump to content

ajax+php if/else form submit problem


keymistress

Recommended Posts

hello all,

i'm a ajax noob so please bear with me.

 

i have a form with a single field to submit an e-mail address. if the e-mail already exists in the database, it will respond "user registered". else, the email will be inserted into the database and respond "you have been registered".

 

the problem now is, the email does get stored in the database but it prompts "user registered" instead of "you have been registered".

 

help!  ???

Link to comment
Share on other sites

i think there's a logic problem...

 

my php file

$email=$_GET["email"];

//check if e-mail is already registered
if ($row[0] == 0)
{
	//register user
	$query2 = "INSERT INTO users (username, userPwd, userAccess) VALUES ('$email', '$userPwd', '$userAccess')";
	echo $query2;
	$result2 = mysql_query($query2);*/

	echo "An e-mail with your username and password has been sent to the address you have entered.";
}
else
{
	//e-mail already registered
	echo "This e-mail has already been registered. Forgot password?";
}

 

my javascript file

var xmlHttp

function showHint(email)
{
if (email.length==0)
  { 
  document.getElementById("userHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getHint.php";
url=url+"?email="+email;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("userHint").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;
}

 

and my HTML form

<html>

<head>

<script src="userHint.js"></script> 

</head>



<body>



<form> 

Email: <input type="text" id="email" onkeyup="showHint(this.value)">

</form>

<p><div id="userHint"></div></p>



</body>

</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.