<?php

mb_internal_encoding('utf-8');
error_reporting(-1);

$student = array();
$example = array('firstName', 'lastName', 'sex', 'section', 'email', 'year', 'exams', 'isLocal');

foreach ($example as $field) {
	$student[] = $_POST[$field];
}

try {
	$DHB = new PDO('mysql:host = localhost;dbname = sat', 'root', '');
	$STH = $DHB->prepare("SELECT email FROM students WHERE email = ?");
	$STH->bindparam(1, $email);
	$email = $_POST['email'];
	print_r($DHB);

	if ($STH->execute()) {
		throw new PDOExpenition("Email is invalid.\n");
	} else {
		 $STH = $DHB->prepare("INSERT into students (firstName, lastName, sex, section, email, year, exams, isLocal) values ($student[0], $student[1],
		 $student[2], $student[3], $student[4], $student[5], $student[6], $student[7])");
		$STH->execute();
	}
}
catch (PDOExpenition $e) {
	echo "error";
}
?>