Jump to content

registration...error reporting in array not working?


localhost

Recommended Posts

[code]$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));

// 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.";
}

}

}[/code]


Link to comment
Share on other sites

Um dont just post the code. What do you want? Please explain whats wrong with your script and what you are trying to do. Also post what the script is supposed to do. Edit the post above to add this in.

When you post coder please use the code tags. ([ code][ /code] (without the spaces before [))
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.