Preface: this will eventually expand to a signup sheet, but I am more concerned with getting one portion completed first.
Now you will not be able to connect to my server, but I do need help, or at least an explanation of why this code isn't working. I have been working on this for a week or so, and have found nothing really similar to my problem.
HTML:
<html>
<head>
<script type="text/javascript" src="checking.js"></script>
</head>
<body>
<span id="conTest">
<?php
$con = mysqli_connect("L28-6","turkey","supersecretpassword","stored");
if (mysqli_connect_errno($con))
{
echo"Failed to connect to MySQL: " . mysqli_connect_error();
} else {
echo "success";
}
?>
</span>
Email: <input type="text" id="email" onkeyup="emailCheck(this.value)"/>
<br/>
<span id="emailError"></span>
</body>
</html>
The main error is somewhere in the js which looks like:
function emailCheck(inputvalue)
{
var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
var span=document.getElementById("emailError");
if(pattern.test(inputvalue))
{
span.innerHTML="true..checking";
var myRequest = new XMLHttpRequest();
var response = myRequest.reponseText;
myRequest.onreadystatechange = function()
{
if(myRequest.readyState == 4 && myRequest.status == 200)
{
if(response.test(inputvalue))
{
span.innerHTML="already in use";
}
else
{
span.innerHTML="valid";
}
}
myRequest.open("POST", "email.php", true);
myRequest.send();
}
}
else
{
span.innerHTML="not valid email";
}
}
The problem is definitely with the ajax call but here is the php portion (which isn't in working condition yet):
<?php
mysqli_query($con,"select user_email from email");
?>
I know its a lot of code, but I really appreciate any input. Also here is the page's response when a properly formed email is used:
Email:asdfasdf@yahoo.com
true..checking
so I know for certain it isn't even dropping into the myRequest.readystatechange function, because if it where it should, at least, return "not valid email".
Your ajax request is inside the readystatechange. This means the ajax request will never be called.
try something like :
function emailCheck(inputvalue)
{
var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
var span=document.getElementById("emailError");
if(pattern.test(inputvalue))
{
span.innerHTML="true..checking";
var myRequest = new XMLHttpRequest();
var response = myRequest.reponseText;
myRequest.onreadystatechange = function()
{
if(myRequest.readyState == 4 && myRequest.status == 200)
{
if(response.test(inputvalue))
{
span.innerHTML="already in use";
}
else
{
span.innerHTML="valid";
}
}
}
myRequest.open("POST", "email.php", true);
myRequest.send();
}
else
{
span.innerHTML="not valid email";
}
}
I can see another issue with your code. The email will be valid even before finish to be filled
something@domain.c will be valid even if i need to informe something@domain.com. Use a button to request the validation