<?PHP

$sql_error = 'SQL Error : ';

$fpassword = htmlentities($_POST[PASSWORD], ENT_QUOTES);
$femail = htmlentities($_POST[EMAIL], ENT_QUOTES);

//--------------------------

$SQL = "SELECT * from USERS WHERE EMAIL = '$_POST[EMAIL]'"; 
$result = @mysql_query( $SQL ); $row = @mysql_fetch_array( $result );

if ($_POST[PASSWORD] != $_POST[PASSWORD2]) {
        $check = fail; $reason = "Passwords do not match.";
        $return = "register";
}

if ($check != fail) {

if ($row[EMAIL] != $nil)
        $check = fail; $reason = "That email address is already in use.";
        $return = "register";

}

if ($check != fail) {
        $sql            = "INSERT INTO USERS SET
        PASSWORD        = '$fpassword',
        USERNAME        = '$femail',
        EMAIL           = '$femail'";

$query = mysql_query($sql) or die("$sql_error" . mysql_error());
$reason = pass;

$SQL = "SELECT * from USERS WHERE EMAIL = '$_POST[EMAIL]'"; 
$result = @mysql_query( $SQL ); $row = @mysql_fetch_array( $result );
        sendmail("$row[EMAIL]","$rowxxx[EMAIL]","Author Account Created! Your Access Information: $rowxxx[TITLE]","Thank you for registering. Your account login details are included below.<BR><BR>Email Address : <B>$_POST[USERNAME]</B><BR>Password : <B>$_POST[PASSWORD]</B><BR><BR><i>$rowxxx[TITLE]</i>");
$_SESSION['EMAIL']   = "$row[EMAIL]";
        $return = "";
}
$return = register;
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>One moment please...</title>
<meta http-equiv="REFRESH" content="0;url=index.php?page=<?php echo $return; ?>&reason=<?php echo $reason; ?>"></HEAD>
<BODY></BODY>
</HTML>

