<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Regiter for the Communicator</title>
</head>
<body>
<center>
<?php
// set your infomation.
include ("config.php");
//include ("config.php");
include ("style.css");
include ("functions.inc");

// connect to the mysql database server.
//mysql_connect ($dbhost, $dbusername, $dbuserpass);
//mysql_select_db($dbname) or die("Cannot select database");

//Are they just getting here or submitting their info?
if (isset($_POST["username"])) {
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$cpassword = $_POST["cpassword"];
$email = $_POST["email"];
//Was a field left blank?
if($username==NULL|$password==NULL|$cpassword==NULL|$email==NULL) {
echo "A field was left blank.";
}else{
//Do the passwords match?
if($password!=$cpassword) {
echo "Passwords do not match";
}else{
//Has the username or email been used?
$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");
$username_exist = mysql_num_rows($checkuser);

$checkemail = mysql_query("SELECT email FROM users WHERE email='$email'");
$email_exist = mysql_num_rows($checkemail);

if ($email_exist>0|$username_exist>0) {
echo "The username or email is already in use";
}else{
//Everything seems good, lets insert.
$query = "INSERT INTO users (username, password, email) VALUES('$username','$password','$email')";
mysql_query($query) or die(mysql_error());
echo "The user $username has been successfully registered.";
}
}
}
}
?>

<h1>Register</h1>
<form action="register.php" method="POST">
<table style="border:1px solid #000000;">
<tr>
<td align="right">
Username: <input type="text" size="15" maxlength="25" name="username">
</td>
</tr>
<tr>
<td align="right">
Password: <input type="password" size="15" maxlength="25" name="password">
</td>
</tr>
<tr>
<td align="right">
Confirm Password: <input type="password" size="15" maxlength="25" name="cpassword">
</td>
</tr>
<tr>
<td align="right">
Email: <input type="text" size="15" maxlength="25" name="email">
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="Register">
</td>
</tr>
<tr>
<td align="center">
<a href="login.php">Login Here</a>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
