I have some data in the database. As i give the email and password it should fetch the database and login. The problem is, from loginform.php file it is navigating to the loginvalidate.php file, but after that it doesn't navigate to another page which I have mentioned in the header() function. As soon as i give the email and password, and hit the login button, it just stops at loginvalidate.php and doesn't proceed to profile.php file. I hope you get it.I donno where the error is, it is neither throwing an error. I'm using WAMP and when I run this code in the browser, the url should display ../../profile.php after hitting the login button, but it shows ../../loginvalidate.php in the URL and the page has nothing to show i.e blank. I have used the md5 function to store passwords in the database. So here also first I have applied the md5 function on the user entered password and then used the password_verify. Is it the password verifying problem or is it anything else ?
loginform.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
</head>
<body>
<form action="includes/loginvalidate.php" method="post">
<div style="margin-top:17%;">
<!--Text box to enter email-id-->
<input id="email" type="email" name="eid" placeholder="E-mail" required/>
<hr style="position:relative; color:white;">
</div>
<div style="margin-top:3%">
<!--Text box to enter password-->
<input id="pwd" type="password" name="password" placeholder="Password" required/>
</div>
<div style="margin-top:15%">
<input type="image" class="mclass" name="loginbt" id="login" src="images/login.png">
</div>
</form>
</body>
includes/loginvalidate.php
<?php
session_start();
try
{
$db = new PDO("mysql:host=localhost;dbname=xxx","yyy","zzz");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_POST['loginbt']))
{
$errmsg='';
$email =$_POST['eid'];
$pass = md5($_POST['password']);
if($errmsg == '')
{
$sql = $db->prepare('SELECT id, email, password from users WHERE email = :email');
$sql->bindParam(':email',$email);
$sql->execute();
$result = $sql->fetch(PDO::FETCH_ASSOC);
if(count($result)>0 && password_verify($pass,$result['password']))
{
header('location: ../profile.php');
exit();
}
else
{
echo '<script language="javascript">';
echo 'alert("Username/Password is incorrect")';
echo '</script>';
}
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>