Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
154
rated 0 times [  160] [ 6]  / answers: 1 / hits: 20637  / 10 Years ago, tue, december 16, 2014, 12:00:00

I want to check the value in text box is present in database and clear the box if the value exists in the database without refreshing the whole page.



HTML:



<p>Email<input type=text name=email id=email size=18 maxlength=50 required></p>


Query:



$echeck=select email from register where email='$email';
$echk=mysql_query($echeck);
$ecount=mysql_num_rows($echk);
if($ecount!=0)
{
echo (<SCRIPT LANGUAGE='JavaScript'>
var asign=document.getElementById(email); //now show null value
asign.value=;
</SCRIPT>);
}


If I use alert it will refresh the page.



window.alert('Email Id already exist');

More From » php

 Answers
5

try to implement something like this:



<script type=text/javascript>
function checkMailStatus(){
//alert(came);
var email=$(#email).val();// value in field email
$.ajax({
type:'post',
url:'checkMail.php',// put your real file name
data:{email: email},
success:function(msg){
alert(msg); // your message will come here.
}
});
}

</script>

<p>Email<input type=text name=email id=email onblur=checkMailStatus()size=18 maxlength=50 required></p>


your php: checkMail.php



$echeck=select email from register where email=.$_POST['email'];
$echk=mysql_query($echeck);
$ecount=mysql_num_rows($echk);
if($ecount!=0)
{
echo Email already exists;
}

[#68476] Friday, December 12, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andrewb

Total Points: 259
Total Questions: 124
Total Answers: 90

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;