Hello,
I am having some trouble with my registration form.
For some reason when i launch my registration for wheter it be on localhost or webhost nothing is displaying on the page.
I get no errors or anything and i cannot detect what is wrong with the script i made.
I am a newbie so if someone could help me and tell me what the problem maybe is?
It is a regsitration form that validates users information, once validation checks have been made and once a check on the database has been done to make sure there are no other username and emal address already exists it is to send the info to the DB.
Problem is nothing is showing, not even the form, i just get a blank white page. I have gone over it so many times and still cannot figure out the problem.
Ok here is my code.
<?php include("db_connect.php"); // Database Connection ?>
<?php
if (isset($_POST['submitted'])) { // Handle the form.
// Website Name
$site = "My Website";
// Get User Data From Form
$username = htmlspecialchars( stripslashes( strip_tags($_POST['username'] ) ) );
$first_name = htmlspecialchars( stripslashes( strip_tags($_POST['first_name'] ) ) );
$last_name = htmlspecialchars( stripslashes( strip_tags($_POST['last_name'] ) ) );
$email = htmlspecialchars( strtolower( stripslashes( strip_tags($_POST['email1'] ) ) ) );
$email_2 = htmlspecialchars( strtolower( stripslashes( strip_tags($_POST['email2'] ) ) ) );
$password = htmlspecialchars( trim($_POST['pass1'] ) );
$password_2 = htmlspecialchars( trim($_POST['pass2'] ) );
$date_time = date('l F Y, g:i:s: A');
// Form Validation
if ( empty ($_POST['username'] ) ) { // Check if username field is empty. If it is tell them
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>Please Enter a Username</p></font>";
$err++;
}
if ( empty ($_POST['first_name'] ) ) { // Check if first name field is empty. If it is tell them
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>Please Enter Your First Name</p></font>";
$err++;
}
if ( empty ($_POST['last_name'] ) ) { // Check if last name field is empty. If it is tell them
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>Please Enter Your Last Name</p></font>";
$err++;
}
if ( empty ($_POST['email1'] ) ) { // Check if email field is empty. If it is tell them
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>Please Enter your email address</p></font>";
$err++;
}
if ( empty ($_POST['email2'] ) ) { // Check if confirm email field is empty. If it is tell them
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>Please Confirm your email address</p></font>";
$err++;
}
if ($_POST['email1'] != $_POST['email2']) { // Check if both emails match. If they are not the same tell them
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>Your Email address does not match</p></font>";
$err++;
}
if ( empty ($_POST['pass1'] ) ) { // Check if password field is empty. If it is tell them
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>Please Enter a Password</p></font>";
$err++;
}
if ( empty ($_POST['pass2'] ) ) { // Check if confirm password field is empty. If it is tell them
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>Please Confirm Your Password</p></font>";
$err++;
}
if ($_POST['pass1'] != $_POST['pass2']) { // Check if both password match. If they are not the same tell them
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>Your Paswords do not match</p></font>";
$err++;
}
$testuser = mysql_query("SELECT * FROM userinformation WHERE `username` = '$username'");
if( @mysql_num_rows( $testuser ) > 0 ) {
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>That username is already in use.</p></font>";
$err++;
}
$testemail = mysql_query("SELECT * FROM userinformation WHERE `email` = '$email'");
if( @mysql_num_rows( $testemail ) > 0 ) {
echo "<font color=\"#FF3F00\" face=\"Verdana, Geneva, sans-serif\"><p>That email address is already in use.</p></font>";
$err++;
}
// If user passes Validation give them a nice little message and send then an email with login details :)
if( $err == 0 ) {
$query = "INSERT INTO userinformation (username, first_name, last_name, email, password, date_time) VALUES ('$username', '$first_name', '$last_name', '$email', '$password', '$date_time')";
// Details to be sent with email
$subject = "Your Login Details for $site";
$headers = "From: $site \r\n";
$headers .= "content-type: text/html \r\n";
$message .= '<h1>Thank-you for registering with us at $site</h1>';
$message .= '<p>Below is your Username and Password you signed up with. Please keep these safe incase you forget them.</p>';
$message .= '<p>Username: '.$username.'</p>';
$message .= '<p>Password: '.$_POST['pass1'].'</p>';
$message .= '<p>Thanks as always,</p>';
$message .= '<p>$site</p>';
// Mail the user
mail( $email, $subject, $message, $headers );
// Dispplay message
echo "<font color=\"#007FAA\" face=\"Arial, Helvetica, sans-serif\"><p>Thank you <b>$first_name $last_name!</b> You have successfully registered an account with us at <b>$site</b> An email with your login details has been sent to <b>$email</b>.</p></font>";
} else {
?>
<h1><font color="#007FAA" face="Verdana, Geneva, sans-serif">Register</font></h1>
<form action="register.php" method="post">
<fieldset>
<p><b><font color="#007FAA" face="Arial, Helvetica, sans-serif">*Username:</font></b> <input type="text" name="username" size="20" maxlength="20" value="<?php if (isset($_POST["username"])) { echo htmlspecialchars($_POST["username"]); } ?>" /></p>
<p><b><font color="#007FAA" face="Arial, Helvetica, sans-serif">*First Name:</font></b> <input type="text" name="first_name" size="20" maxlength="40" value="<?php if (isset($_POST["first_name"])) { echo htmlspecialchars($_POST["first_name"]); } ?>" /></p>
<p><b><font color="#007FAA" face="Arial, Helvetica, sans-serif">*Last Name:</font></b> <input type="text" name="last_name" size="20" maxlength="50" value="<?php if (isset($_POST["last_name"])) { echo htmlspecialchars($_POST["last_name"]); } ?>" /></p>
<p><b><font color="#007FAA" face="Arial, Helvetica, sans-serif">*Email Address:</font></b>
<input type="text" name="email1" size="30" maxlength="50" value="<?php if (isset($_POST["email1"])) { echo htmlspecialchars($_POST["email1"]); } ?>" /></p>
<p><b><font color="#007FAA" face="Arial, Helvetica, sans-serif">*Confirm Email Address:</font></b>
<input type="text" name="email2" size="30" maxlength="50" value="<?php if (isset($_POST["email2"])) { echo htmlspecialchars($_POST["email2"]); } ?>" /></p>
<p><b><font color="#007FAA" face="Arial, Helvetica, sans-serif">*Password:</font></b>
<input type="password" name="pass1" size="20" maxlength="20" /> </p>
<p><b><font color="#007FAA" face="Arial, Helvetica, sans-serif">*Confirm Password:</font></b> <input type="password" name="pass2" size="20" maxlength="20" /></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Register" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html>
<?php
}
}
?>
Thank you,
genieuk