<?php
	//start PHP session
	session_start();

	//check if login form is submitted
	if(isset($_POST['submit1'])){
		//assign variables to post values
		$email = $_POST['usernm'];
		$password = $_POST['pword'];

		//include our database connection....................................................................
$db_host="localhost"; //localhost server 
$db_user="ki223469_temp"; //database username
$db_password="m0bi.2018$"; //database password   
$db_name="ki223469_temp"; //database name

try
{
 $db=new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_password);
 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOEXCEPTION $e)
{
 $e->getMessage();
}
///.......................................................................................................

		//get the user with email
		$stmt = $pdo->prepare('SELECT * FROM airtime_customer WHERE username = :email and user_type="normal"');
		echo "eeeeeeee";
		try{
			$stmt->execute(['email' => $email]);
	echo "eeeeeeee";
			//check if email exist
			if($stmt->rowCount() > 0){
				//get the row
				$user = $stmt->fetch();

				//validate inputted password with $user password
				if(password_verify($password, $user['password'])){
					//action after a successful login
					//for now just message a successful login
					$_SESSION['success'] = 'User verification successful';
			
				}
				else{
					//return the values to the user
					$_SESSION['email'] = $email;
					$_SESSION['password'] = $password;
	                $_SESSION['log_id'] = $user['password']; 
					$_SESSION['error'] = 'Incorrect password';
					header('location: indexd.php');
				}

			}
			else{
				//return the values to the user
				$_SESSION['email'] = $email;
				$_SESSION['password'] = $password;

				$_SESSION['error'] = 'No account associated with the email';
			}
			
		}
		catch(PDOException $e){
			$_SESSION['error'] = $e->getMessage();
		}
		
	}
	else{
		$_SESSION['error'] = 'Fill up login form first';
	}

	header('location: index.php');
?>