Please help me fix this php script?

jacob.irwin

New member
Trying to complete this registration for my website..

Error I am getting is: Registration Failed

We're sorry, but an error has occurred and your registration for the username [email protected], could not be completed.
Please try again at a later time.

Will someone look over my code and tell me what is wrong:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
session_start();
include("database.php");

/**
* Returns true if the email has been taken
* by another user, false otherwise.
*/
function emailTaken($email){
global $conn;
if(!get_magic_quotes_gpc()){
$email = addslashes($email);
}
$q = "select email from users where email = '$email'";
$result = mysql_query($q,$conn);
return (mysql_numrows($result) > 0);
}

/**
* Inserts the given (email, password) pair
* into the database. Returns true on success,
* false otherwise.
*/
function addNewEmail($email, $password){
global $conn;
$q = "INSERT INTO users VALUES ('$email', '$password')";
return mysql_query($q,$conn);
$q = "INSERT INTO virtuala VALUES ('$email')";
return mysql_query($q,$conn);
}

/**
* Displays the appropriate message to the user
* after the registration attempt. It displays a
* success or failure status depending on a
* session variable set during registration.
*/
function displayStatus(){
$email = $_SESSION['regemail'];
if($_SESSION['regresult']){
?>

<h1>Registered!</h1>
<p>Your <b><? echo $email; ?></b>, your information has been added to Grouplete, you may now <a href="index.php" title="Login">log in</a>.</p>

<?
}
else{
?>

<h1>Registration Failed</h1>
<p>We're sorry, but an error has occurred and your registration for the username <b><? echo $email; ?></b>, could not be completed.<br>
Please try again at a later time.</p>

<?
}
unset($_SESSION['regemail']);
unset($_SESSION['registered']);
unset($_SESSION['regresult']);
}

if(isset($_SESSION['registered'])){
/**
* This is the page that will be displayed after the
* registration has been attempted.
*/
?>
<html>
</head>

<body>
<? displayStatus(); ?>
</body>


</html>

<?
return;
}

/**
* Determines whether or not to show to sign-up form
* based on whether the form has been submitted, if it
* has, check the database for consistency and create
* the new account.
*/
if(isset($_POST['subjoin'])){
/* Make sure all fields were entered */
if(!$_POST['email'] || !$_POST['password'] || !$_POST['fullname'] || !$_POST['birthday'] || !$_POST['birthmonth'] || !$_POST['birthyear'] || !$_POST['gender']){
die('You must completely fill out all fields to register. Please try signing up again.');
}

/* Spruce up username, check length */
$_POST['email'] = trim($_POST['email']);
if(strlen($_POST['email']) > 40){
die("Sorry, the email you provided is longer than 40 characters, please shorten it.");
}

/* Check if username is already in use */
if(mysql_num_rows($email) > 0) { //check if there is already an entry for that username
echo "Already taken";
}

if(!$_POST['email']){
die('You did not fill in the email field');
}
/* Add the new account to the database */
$md5pass = md5($_POST['password']);
$_SESSION['regemail'] = $_POST['email'];
$_SESSION['regresult'] = addNewEmail($_POST['email'], $md5pass);
$_SESSION['registered'] = true;
header("Location: ".getenv('http_referer'));
return;
}
else{
?>

<html>
<title>Sign Up</title>
<body>
<img src="Images/Grouplete Logo.JPG" /><br /><br />
<FONT FACE="Rockwell" color="#666666"SIZE="5"><b>Sign Up</b></FONT><br /><br />
<FONT FACE="Rockwell" color="#666666"SIZE="4">It's free and anyone is welcome to join</FONT><br /><br />
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="left" border="0" cellspacing="5" cellpadding="3&quo
 
Back
Top