<?php
$page_title = 'Register';
include ('./includes/header.html');
if (isset($_POST['submitted'])) {
$errors = array();
if (empty($_POST['first_name'])) {
$errors[] = ' You forgot to enter your first name.';
} else {
$fn = trim($_POST['first_name']);
}
if (empty($_POST['last_name'])) {
$errors[] = ' You forgot to enter your last name.';
} else {
$ln = trim($_POST['last_name']);
}
if (empty($_POST['email'])) {
$errors[] = ' You forgot to enter your email address.';
} else {
$e = trim($_POST['email']);
}
if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST['password2']) {
$errors[] = ' Your password did not match the confirmed password.';
} else {
$p = trim($_POST['password1']);
}
} else {
$errors[] ='You forgot to enter your password.';
}
if (empty($errors)) {
require_once ('mysql_connect.php');
$query = "SELECT user_id FROM users WHERE email = '$e'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
$query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES
('$fn','$ln', '$e', SHA('$p'), NOW() )";
$result = @mysql_query ($query);
if ($result) {
echo '<h1 id="mainhead">Thank you !</h1>
<p>You are now registered. In Chapter 9 you will actually be able to log in !</p><p></p>';
include ('./includes/footer.html');
exit();
} else {
echo '<h1 id="mainhead">System Error</h1>
<p class="error"You could not be registered due to system error. We apologize for any inconvenience. </p>';
echo '<p>' . mysql_error() . 'Query : ' . $query . '</p>';
include ('./includes/footer.html');
exit();
}
} else{
echo '</h1 id=”mainhead”> Error! </h1>
<p class=”error”>The email address has already been registered.</p>';
}
mysql_close();
} else {
echo '<h1 id="mainhead">Error !</h1>
<p class="error">The following error(s) occurred :';
foreach ($errors as $msg) {
echo " - $msg\n";
}
echo '</p><p>Please try again.</p><p></p>';
}
}
?>
<h2>Register</h2>
<form action="register.php" method="post">
<p>First Name : <input type="text" name="first_name" size="15" maxlength="15"
value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p>Last Name : <input type="text" name="last_name" size="15" maxlength="30"
value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
<p>Email Address : <input type="text" name="email" size="20" maxlength="40"
value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p>Password : <input type="password" name="password1" size="10" maxlength="20" /></p>
<p>Confirm Password : <input type="password" name="password2" size="10" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./includes/footer.html');
?>
?>

