Slip 14 - B) Write a PHP script using AJAX concept, to check user name and password are valid or Invalid (use database to store user name and password).

 Solution:

Html file -

<html>
<head>
<script type="text/javascript">
function Addition()
{
var ob=false;
ob=new XMLHttpRequest();
var no1=document.getElementById("no1").value;
var no2=document.getElementById("no2").value;
ob.open("GET","Que25.php?num1="+no1+"&num2="+no2);
ob.send();
ob.onreadystatechange=function()
{
if(ob.readyState==4 && ob.status==200)
document.getElementById("add").innerHTML=ob.responseText;
}
}
</script>
</head>
<body>
Enter User Name :<input type=text id="no1">
Enter Password :<input type=text id="no2">
<input type=button name=submit value=add onClick="Addition()">
<span id="add"></span>
<body>
</html>

Php File-

<?php
$una=$_GET['num1'];
$ps=$_GET['num2'];
$sn="localhost";
$un="root";
$pas="";
$dbn="s17";
if((!empty($una)) && (!empty($ps)))
{
$con=mysqli_connect($sn,$un,$pas,$dbn);
$sql="select * from login where un='$una' and pass='$ps'";
$r=mysqli_query($con,$sql);
if (mysqli_num_rows($r) > 0)
{
echo "Login";
}
else
{
echo "Not";
}
}
else
{
echo "enter both Username& pass";
}
?>

Post a Comment

0 Comments