Registering
Posted: Tue Jul 05, 2011 8:47 pm
<?php if (isset($_POST['name'], $_POST['username'], $_POST['password'], $_POST['repeatpass'], $_POST['email'])){ $name = $_POST['name']; $username = $_POST['username']; $password = $_POST['password']; $repeatpass = $_POST['repeatpass']; $email = $_POST['email']; //set error conditions $errors = array(); if ((empty($name) || empty($username) || empty($password) || empty($repeatpass) || empty($email) === true)){ $errors[] = "Please fill in every field."; } if (strlen($username)>25 || strlen($username)<3){ $errors[] = "Username must be between 3 and 25 characters."; } if (($repeatpass != $password) === true){ $errors = "Passwords don't match!"; } if (strlen($password) < 2 || strlen($password) > 15){ $errors[] = "Password must be between 2 and 25 characters."; } if ((ctype_alnum($username) || ctype_alnum($password)) === false){ $errors[] = "Password and username must use only letters and numbers."; } if ((filter_var($email, FILTER_VALIDATE_EMAIL)) === false){ $errors = "Please enter a valid email address."; } if (empty($errors)){ register($name, $username, $password, $email); echo "You have successfully registered!"; }else{ ?> <p>Failure in registering.</p> <ul> <?php foreach ($errors as $error){ echo "<li>$error</li>\n"; } ?> </ul> <?php } } ?>
what's the problem?Error wrote:Warning: Invalid argument supplied for foreach() in /Users/jon/Sites/user/register.php on line 43