How to check multiple field if fields are in the database and echo "OK" if not then "invalid"
Here is my the html code
<html>
<head>
<script src="Bootstrap/js/jquery.min.js"></script>
<script src="Bootstrap/js/bootstrap.min.js"></script>
<script src="Bootstrap/js/npm.js"></script>
<script type="text/javascript">
function checkname()
{
var name=document.getElementById( "UserName" ).value;
if(name)
{
$.ajax({
type: 'post',
url: 'checkdata.php',
data: {
user_name:name,
},
success: function (response) {
$( '#name_status' ).html(response);
if(response=="OK")
{
return true;
}
else
{
return false;
}
}
});
}
else
{
$( '#name_status' ).html("");
return false;
}
}
function checkemail()
{
var email=document.getElementById( "UserEmail" ).value;
if(email)
{
$.ajax({
type: 'post',
url: 'checkdata.php',
data: {
user_email:email,
},
success: function (response) {
$( '#email_status' ).html(response);
if(response=="OK")
{
return true;
}
else
{
return false;
}
}
});
}
else
{
$( '#email_status' ).html("");
return false;
}
}
function checkall()
{
var namehtml=document.getElementById("name_status").innerHTML;
var emailhtml=document.getElementById("email_status").innerHTML;
if((namehtml && emailhtml)=='OK')
{
return true;
}
else
{
return false;
}
}
</script>
</head>
<body>
<form method="POST" action="insertdata.php" onsubmit="return checkall();">
<input type="text" name="username" id="UserName" onkeyup="checkname();">
<span id="name_status"></span>
<br>
<input type="text" name="useremail" id="UserEmail" onkeyup="checkemail();">
<span id="email_status"></span>
<br>
<input type="password" name="userpass" id="UserPassword">
<br>
<button type="submit" name="submit_form" value="Submit">Submit</button>
</form>
</body>
</html>
here is the checkdata.php
<?php
$servername = "localhost";
$username = "root";
$password = "louchin";
$dbname = "demo";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<?php
if(isset($_POST['user_name']) && isset($_POST['user_email'])){
$name=$_POST['user_name'];
$emailId=$_POST['user_email'];
$checkdata="SELECT name,loginid FROM user WHERE name='$name' AND loginid='$emailId' ";
$query=mysqli_query($conn, $checkdata);
if(mysqli_num_rows($query) > 0)
{
echo "User Name Already Exist";
}
else
{
echo "OK";
}
exit();
}
?>
To be more clearer, I want to achieve is that the values of the name and email from the database is equals to the inputted value. And it will only display a single "OK". Just started using ajax. Please help. Ty