I have done the following changes
Login.php
Code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Login with jQuery AJAX</title>
<script type="text/javascript" src="js/jquery-1.6.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#login").click(function(){
var username=$("#username").val();
var password=$("#password").val();
$.ajax({
type:"POST",
url:"loginpost.php",
data:"username=" + username + "&password=" + password,
success : function(result){
if(result == "correct")
{
$(document.location = "members.php");
}else
{
$(".errors").html("incorrect credential");
}
}
});
return false;
});
});
</script>
</head>
<body>
<p> </p>
<div id="content">
<h1>Login Form</h1>
<form action="" method="post">
<p>
<label for="username">Username: </label>
<input type="text" name="username" id="username" />
</p>
<p>
<label for="password">Password: </label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="submit" id="login" name="login" />
</p>
</form>
<div class="errors">
Press Login
</div>
</div>
</body>
</html>
Loginpost.php
Code:
<?php
include_once "conndb1.php";
if($_POST)
{
$username = ($_REQUEST['username']);
$password = md5($_REQUEST['password']); // use encode of your choice here
$sql=mysql_query("select email from register1 where username='$username' AND password='$password'") or die(mysql_error());
if(mysql_num_rows($sql) == 1)
{
echo "correct";
$info = mysql_fetch_assoc($sql);
$email = $info["email"];
$expire=time()+ 86400;
setcookie("username",$username,$expire);
setcookie("email",$email,$expire);
}else{
echo "incorrect credential";
}
}
?>
It still dosen't work it slips to incorrect credential.I have also check the entries in database.