<?
session_start();
include 'dbconnect.php';
$email = $_POST['uname'];
$submit = $_POST['submit'];
if ($submit == 'Submit'){
$password = md5(md5( md5(trim($_POST['pword']))));
if ($password){
$sql = $dbh->prepare("select id from users  where email =? and credentials = ? and active = '1'");
$sql->execute(array($email,$password));
$match = 0;
while ($row = $sql->fetch()){
	$id = $row['id'];
$match++;	
}
if ($match > 0) {
$_SESSION['approved'] = 'yes';
$_SESSION['id'] = $id;
$upsql = $dbh->prepare("update users set lastlogin = now() where email = ?");
$upsql->bindValue(1,$email);
$upsql->execute();


header("Location: index.php");
}
else
{
echo 'try it again!';	
}
}
}

 ?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action = "login.php" method = "post">
Email<input type = "text" name="uname" /><br/>
Password <input type = "text" name="pword" /><br/>
<input type = "submit" name = "submit" value = "Submit"/>
</form>
</body>
</html>