I am creating a php login and register page when i go to register using the code below, i dont get any errors but it gives me the messages: “You didn’t enter a username”, “You didn’t enter a first name” and You didn’t enter a last name.” when they have clearly been entered. Any reason why it wont read the info for these three things?
<?php
//Check if the form has been submitted
require_once(‘config.inc.php’);
$page_title = ‘Register’;
include(‘header.html’);
if(isset($_POST[‘submitted’])){
require_once(‘mysql_connect.php’);
$errors = array();//Initaliaze error away
//Check for a username
if (eregi (‘^[[:alpha:].’-] {5,15}$’, stripslashes(trim($_POST[‘username’])))){
$un = escape_data($_POST[‘username’]);
} else{
$un = FALSE;
echo ‘<p><font color =”red” size=”+1″>Please enter a username!</font></p>’;
}
//Check for a first name
if (eregi (‘^[[:alpha:].’-] {2,15}$’, stripslashes(trim($_POST[‘first_name’])))){
$fn = escape_data($_POST[‘first_name’]);
} else{
$fn = FALSE;
echo ‘<p><font color =”red” size=”+1″>Please enter your first name!</font></p>’;
}
//Check for a last name
if (eregi (‘^[[:alpha:].’-] {2,30}$’, stripslashes(trim($_POST[‘last_name’])))){
$ln = escape_data($_POST[‘last_name’]);
} else{
$ln = FALSE;
echo ‘<p><font color =”red” size=”+1″>Please enter your last name!</font></p>’;
}
//Check for an email address
if (eregi (‘^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+.[a-z]{2,4}$’, stripslashes(trim( $_POST[’email’])))){
$e = escape_data($_POST[’email’]);
} else{
$e = FALSE;
echo ‘<p><font color=”red” size=”+1″>Please enter a valid email address!</font> </p>’;
}
//Check for a password and match against the confirmed password.
if (eregi (‘^[[:alnum:]]{4,20}$’, stripslashes(trim($_POST[‘password1’])))){
if($_POST[‘password1’] == $_POST[‘password2’]) {
$p = escape_data($_POST[‘password1’]);
} else{
$p = FALSE;
echo ‘<p><font color=”red” size=”+1″>Your password did not match the confirmed password!</font></p>’;
}
} else{
$p = FALSE;
echo ‘<p><font color=”red” size=”+1″>Please enter a valid password!</font></p>’;
}
if ($un && $fn && $ln && $e && $p){ //If everything’s ok
//make sure the email address is available
$query = “SELECT user_id FROM users WHERE email=’$e'”;
$result = mysql_query ($query) or trigger_error(“Query: $queryn<br/>MySQL Error: ” . mysql_error());
if (mysql_num_rows($result) == 0) { //available
//create activation code
$a = md5(uniqid(rand(), true));
//add the user
$query = “INSERT INTO users (username, email, password, first_name, last_name, active, registration_date) VALUES (‘$un’, ‘$e’, SHA(‘$p’), ‘$fn’, ‘$ln’, ‘$a’, NOW())”;
$result = mysql_query($query) or trigger_error(“Query: $queryn<br/>MySQL Error:” . mysql_error());
if(mysql_affected_rows() == 1) {
//if it ran ok
//send the email
$body = “Thank you for registering at This IZ Jesse.com. To activate your account, please click on this link:nn”;
$body .= “http://www.thisizjesse.com/activate.php?x=”.mysql_insert_id() . “&y=$a”;
mail($_POST[’email’], ‘Registration Confirmation’, $body);
//finish the page
echo ‘<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>’;
exit();
} else{ //if it did not run ok
echo'<p><font color=”red” size=”+1″>You could not be registered due to a system error. We apologize for any inconvienience.</font></p>’;
}
} else{ //the email address is not available
echo ‘<p><font color=”red” size=”+1″>That email address has already been registered. If you have forgotten your password, use the link to have your password sent to you.</font></p>’;
}
} else{ //if one of the data tests failed.
echo ‘<p><font color=”red” size=”+1″>Please try again.</font></p>’;
}
@mysql_close(); //close db
}
?>
<h2>Register</h2>
<form action=”register.php” method=”post”>
<fieldset>
<p>Username: <input type=”text” name=”username” size=”15″ maxlength=”15″ value=”<?php
if(isset($_POST[‘username’])) echo $_POST[‘username’]; ?>” /></p>
<p>First Name: <input type=”text” name=”first_name” size=”15″ maxlength=”15″ value=”<?php
if(isset($_POST[‘first_name’])) echo $_POST[‘first_name’]; ?>” /></p>
<p>Last Name: <input type=”text” name=”last_name” size=”30″ maxlength=”30″ value=”<?php
if(isset($_POST[‘last_name’])) echo $_POST[‘last_name’]; ?>” /></p>
<p>Email Address: <input type=”text” name=”email” size=”40″ maxlength=”40″ value=”<?php
if(isset($_POST[’email’])) echo $_POST[’email’]; ?>” /></p>
<p>Password: <input type=”password” name=”password1″ size=”20″ maxlength=”20″ />
<small>Use only letter and numbers. Must be between 4 and 20 characters long.</small></p>
<p><b>Confirm Password:</b> <input type=”password” name=”password2″ 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>
<?php
include(‘footer.html’);
?>