<!DOCTYPE html>
<head>
	<title>EduAsk</title>
	<style type="text/css">
		 header table{
			width: 100%;
		}
		a:link{
			color: white;
			text-decoration: none;
		}
		.wide{
			width: 30%;
		}
		a:visited{
			color: blue;
		}
	</style>
</head>
<body>

<header style= "background-color: black;" id="top">
<table style="width: 100%">
	<tr>
		<td><a href="index3.html"><img src="logo.png" style="width: 125px;"></a></td>
		<td><a href="login.html">LogIn</a></td>
		<td><a href="signup.html">SignUp</a></td>
		<td style="text-align: center;"><img src="more.png" style="width:50px;"></td>
	</tr>
</table>
</header>

<div>
<h2>Sign Up to ask or answer.</h2>
<form method="post" action="">
	<table style="width: 33%">
		<tr>
			<td><label for="fname">First Name</label></td>
			<td><label for="lname">Last Name</label></td>
		</tr>
		<tr>
			<td><input type="text" name="fname"></td>
			<td><input type="text" name="lname"><br></td>
		</tr>
	</table><br>
	<label for="user">Username</label><br>
	<input type="text" name="user" class="wide"><br><br>
	<label for="email">E-mail Address</label><br>
	<input type="text" name="email" class="wide"><br><br>
	<label for="password">Password</label><br>
	<input type="password" name="password" class="wide"><br><br>
	<label for="repass">Re-type Password</label><br>
	<input type="password" name="password" class="wide"><br><br>
	<input type="radio" name="type"><value="student" checked> Student
	<input type="radio" name="type"><value="teacher" checked> Teacher
	<br><br>
	<input type="submit" value="Sign Up!" style="background-color:rgb(45, 72, 112); width: 110px; height:28px;  color: white">
</form>
</div>

<?php 
//connection model
include ('Connect.php'); 

if(isset($_POST['submit'])){
$fname = $_POST['fname'];
$lrnmame = $_POST['lname'];
$user = $_POST['user'];
$password = $_POST['password'];
$re = $_POST['re-typed'];
$type = $_POST['type']
$email = $_POST['email'];
$comment = "You have filled out the form incorrectly.";
$name = test_input($_POST['fname'])

if ($type == student) {
	$database = "student";
}
else{
	$database = "teacher";
}

if (!preg-match("/^[a-zA-z]*|; fname")) {
	$firstname[rr = "only letters and whitespaces allowed"
}
if (!preg-match("/^[a-zA-z]*|; lname")) {
	$lastame[rr = "only letters and whitespaces allowed"
}
	if(empty($user) || empty($password)  || empty($firstname) || empty($surname) || empty($email) || empty($type) || $re != $password) {
		echo $comment;
	}
	else{
		//sql statement 
		$sql = $conn->query("insert into $database (user, fname, lname, password, email) values ('$user', '$fname', '$lname', '$password', '$email')");
		
		echo '<div class = "alert alert-success" role="alert">Your application was a success.</div>';
	}

} ?>
</header>
</body>
</html>