<?php

include 'db.php';
include 'error.php';


$surname=$_POST["surname"];
$firstname=$_POST["firstname"];
$years=$_POST["years"];
$email=$_POST["email"];
$other=$_POST["other"];

if (empty($surname) || empty($firstname) || empty($years) || empty($email))
{
	include 'header.php';
	?>
			<span class="Head0">Contact Us</span><br>
			<span class="Head1">Become a Member of the ORS</span><p>
			<form name="contact" action="contact_become_member.php" method="post" onSubmit="return checkDetails(this);">

			<table border="0" width="100%" cellpadding="0" cellspacing="5">
			<tr><td width="220"></td><td width="240"></td></tr>
			<tr><td align="right">Surname</td><td>&nbsp;&nbsp;&nbsp;<input type="text" name="surname" size="20"></td></tr>

			<tr><td align="right">First Name</td><td>&nbsp;&nbsp;&nbsp;<input type="text" name="firstname" size="20"></td></tr>

			<tr><td align="right">E-mail Address</td><td>&nbsp;&nbsp;&nbsp;<input type="text" name="email" size="20"></td></tr>

			<tr><td align="right">Years at King's Rochester</td><td>&nbsp;&nbsp;&nbsp;<input type="text" name="years" size="20"></td></tr>

			<tr><td colspan="2"><br>Any Other Details</td></tr>
			<tr><td colspan="2"><textarea name="other" rows="10" cols="45"></textarea></td></tr>

			
			<tr><td colspan="2" align="center"><input type="Submit" value="submit"></td></tr>
			</table></form>

	<?php
	include 'footer.php';

}else
{
	if(!($connection=@mysql_connect($hostName, $dbUsername, $dbPassword)))
		die("Could not connect to DB");

	if(!(mysql_select_db ($databaseName, $connection)))
		showerror();


	$listQuery="SELECT email_value FROM email WHERE email_name='Join'";

	if(!($result = @mysql_query($listQuery,$connection)))
		showerror();

	$row=mysql_fetch_array($result);
	$emailTo=$row['email_value'];
	$emailSubject="ORS Join Enquiry";
	$emailMessage="ORS Membership Enquiry from ".$firstname." ".$surname." at Rochester over period: ".$years.".\nOther details:\n".$other;


	mail($emailTo, $emailSubject, $emailMessage);

	header("Location:contact_thanks.php");



}
?>

