<?php
/* Coopercentral Login 2.0 member registration page
Please fill in the fields below and the run
this page. Once it's installed, please
delete this file
*/
include("functions.php");
echo "<h2 align=\"center\">Member Registration Page</h2>";
if(!isset($_POST[submit])) {
echo "<form method=\"POST\" action=\"".$_SERVER[PHP_SELF]."\">
<center>
<table align=\"center\">
<tr>
<td colspan=2>Please fill out the form below to register for this site.</td>
</tr>
<tr>
<td colspan=> </td>
</tr>
<tr>
<td>First Name</td>
<td><input type=\"text\" name=\"fname\"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type=\"text\" name=\"lname\"></td>
</tr>
<tr>
<td>Username</td>
<td><input type=\"text\" name=\"username\"></td>
</tr>
<tr>
<td>Password</td>
<td><input type=\"password\" name=\"password\"></td>
</tr>
<tr>
<td>Retype Password</td>
<td><input type=\"password\" name=\"verify\"></td>
</tr>
<tr>
<td>Email Address</td>
<td><input type=\"text\" name=\"email\"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=\"submit\" name=\"submit\" value=\"submit\"></td>
</tr>
</table>";
} else if(isset($_POST[submit]) && empty($_POST[fname]) or empty($_POST[lname]) or empty($_POST[username]) or empty($_POST[password]) or empty($_POST[verify]) or empty($_POST[email])) {
echo "<center><font color=\"red\"><b>Please enter all fields in the form</b></font></center>";
} else if(isset($_POST[submit]) && !empty($_POST[fname]) && !empty($_POST[lname]) && !empty($_POST[username]) && !empty($_POST[password]) && !empty($_POST[verify]) && !empty($_POST[email])) {
//once all fields are in, must check a few constraints
//check for existing username
//usernames should be at least 6 characters in length, but less than 15
//password should be at least 8 characters in length
//passwords need to be the same
//email must be valid
if(db_num("$users_table","username='".$_POST[username]."'") == "1") {
$error[] = "This username already exists";
}
if(!checkEmail($_POST[email])) {
$error[] = "Please enter a valid email address";
}
if(strlen($_POST[username]) < 6 || strlen($_POST[username]) > 15) {
$error[] = "The username must be between 6 and 15 characters in length";
}
if(strlen($_POST[password]) < 8) {
$error[] = "The password needs to be at least 8 charactres in length";
}
if($_POST[password] != $_POST[verify]) {
$error[] = "The passwords you entered don't match";
}
if(count($error) > 0) {
echo "<center><table>
<tr>
<td>The following errors have occured while processing your member registration:<ul>";
for($x = 0; $x < count($error); $x++) {
echo "<li><font color=\"red\"><b>".$error[$x]."</b></font></li>";
}
echo "</ul></td></tr></table>
<p align=\"center\"><a href=\"".$_SERVER[PHP_SELF]."\">Please try again</a></center>";
} else if(count($error) < 1) {
$result = @mysql_query("INSERT INTO $users_table VALUES ('','".$_POST[username]."','".md5($_POST[password])."','".$_POST[fname]."','".$_POST[lname]."','".$_POST[email]."','1','".time()."')");
echo "<h3>Username successfully added!</h3>
Thank you for signing up with the username <b>$_POST[username]</b>. You can <a href=\"http://".$_SERVER[SERVER_NAME]."\">return to the homepage</a>";
}
}
?>