Registering

Post here is you are having problems with any of the tutorials.
Post Reply
JelvinJS7
Posts: 341
Joined: Thu May 12, 2011 8:40 pm

Registering

Post by JelvinJS7 »

<?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
            }
            
        }
?>
Error wrote:Warning: Invalid argument supplied for foreach() in /Users/jon/Sites/user/register.php on line 43
what's the problem?
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Registering

Post by Tino »

On line 26 in the code you posted, you set the error variable to a string if no valid email address was supplied. You also do this on line 17. You should use that bracket notation you use on the other lines to make sure the errors get added to the $errors array.
$errors[] = 'string';
Please check out my CodeCanyon items.
JelvinJS7
Posts: 341
Joined: Thu May 12, 2011 8:40 pm

Re: Registering

Post by JelvinJS7 »

Tino wrote:On line 26 in the code you posted, you set the error variable to a string if no valid email address was supplied. You also do this on line 17. You should use that bracket notation you use on the other lines to make sure the errors get added to the $errors array.
$errors[] = 'string';
Oh I see. :oops: hehe. Thanks!
How did I miss that?…
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Registering

Post by Tino »

I don't know ;)

But you're welcome, anyway.
Please check out my CodeCanyon items.
Post Reply