Alright, I am trying to make it so all the errors get stored into an array, and then if there are any errors, it lists them all from the array. For some reason absolutely none of the strlen restrictions are working, nor is the array. Any ideas? Thanks.
$error = array();
if (isset($_POST['submit']) && !empty($_POST['user_name']) && !empty($_POST['pass1'])
&& !empty($_POST['pass2']) && !empty($_POST['email'])) {
// Define POST variables
$user_name = stripinput(trim($_POST['user_name']));
$pass1 = stripinput(trim($_POST['pass1']));
$pass2 = stripinput(trim($_POST['pass2']));
$email = stripinput(trim($_POST['email']));
$hide_email = stripinput(trim($_POST['hide_email']));
// Check if username is already in use
$sql_check_user = query("SELECT user_name FROM `" . $config['table_prefix'] . "members` WHERE user_name = '$user_name'");
$sql_num_user = num_rows($sql_check_user);
if ($sql_num_user >= 1) {
$error[] = 'Username ' . $user_name . ' already in use.';
}
if (strlen($user_name) < 4 || strlen($user_name) > 16)
{
$error[] = 'Username must be more than 4 characters, but less than 16. Your username is currently ' . strlen($user_name) . ' characters long.';
}
// Check if Email address is already in use
$sql_check_email = query("SELECT email FROM `" . $config['table_prefix'] . "members` WHERE email = '$email'");
$sql_num_email = num_rows($sql_check_email);
if ($sql_num_email >= 1) {
$error[] = 'Email Address ' . $email . ' already in use.';
}
if (strlen($email) < 12 || strlen($email) > 35)
{
$error[] = 'Email Address must be within 12 and 35 characters, your email is currently ' . strlen($email) . ' characters.';
}
// Make sure both passwords entered are identical
if ($pass1 != $pass2) {
$error[] = 'The passwords entered do not match.';
}
// Make sure Email address is in valid format
if (!eregi("[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}",$email)) {
$error[] = 'Email address format is not valid.';
}
// Encrypt password using sha1();
$password = sha1($pass1);
// Generate random activation key
$act = rand(1, 99999);
$act_key = md5($act);
// Create login key
$stepkey = randomkeys(32);
$step2 = base64_encode($stepkey);
$loginkey = md5(sha1($step2));
// make sure its not in use for the one used for thisr egistration
$sel = query("SELECT `loginkey` FROM `" . $config['table_prefix'] . "members` WHERE `loginkey` = '$loginkey'");
$isit = num_rows($sel);
if ($isit >= 1)
{
// if its already in use...generate a new one and hope its not in use!
$stepkey = randomkeys(32);
$step2 = base64_encode($stepkey);
$loginkey = md5(sha1($step2));
}
// Insert details into database table
if(count($error) > 0) {
foreach($error as $key => $value) {
$alert .= $value;
}
$sql_insert_user = query("INSERT INTO `" . $config['table_prefix'] . "members` (`user_name`, `password`, `email`, `regip`,
`hide_email`, `join_date`, `act_key`, `usergroupID`, `loginkey`) VALUES ('$user_name', '$password', '$email', '$ip_address', '$hide_email', '$time', '$act_key', '0', '$loginkey')");
$to=$email;
$subject="Thank you for signing up to site name !";
$header="From: Administration <$SITE_URL>";
$message="Your Activation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://$SITE_URL/activate.php?key=$act_key";
$sentmail = mail($to,$subject,$message,$header);
if ($sentmail) {
$alert = "An email has been dispatched to $email in order to activate your user account.";
}
}
}
$tplObj = new tplSys("./");
$tplObj->getFile( array(
'register' => "templates/$template_directory/register.tpl" )
);
$self = $PHP_SELF;
// Display it all!
$tplObj->varRef( "register", array(
"TITLE" => "$boardname",
"BOARDNAME" => "<a href=\"index.php\">$boardname</a>",
"USERNAME" => "$loggedin",
"LINKS" => "$links",
"CURRENTTIME" => "$currenttime",
"SELF" => "member.php?do=register"
)
);
$tplObj->parseDynamic("register");