problem to do the trick

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

sendy
New php-forum User
New php-forum User
Posts: 9
Joined: Thu Oct 25, 2012 9:47 pm

problem to do the trick

Postby sendy » Sat Dec 22, 2012 7:19 am

example i have a form validation script which test if user has filled all of the fields.
i set up the $errors variable, and test each field if they have errors or not

Code: Select all

$errors;
$required_fields = array('username' , 'password', 'email');
foreach($required_fields as $field)
{
     if(empty($_POST[$field]))
     {
        $errors[] = "Please fill {$_POST[$field]}";
     }
}

then i want to:
Add code to the handling of the $errors variable on the page that uses a foreach loop if $errors is an array, or just prints the value of $errors otherwise.

what im thinking is using is_array() function, to test $errors :

Code: Select all

if( is_array($errors) )



then i tried to use var_dump() to test $errors (even if there is only 1 error) unfortunately its still an array.

i cant figure it out..

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests