Very Basic IF statement problem

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Sat Apr 05, 2014 10:09 am

an easy way to do it, is to start with an empty array of messages to be returned, then as each check is run, if it fails, add to the array. once you're done, if the array is not empty, a failure has happened, display messages. something like:

Code: Select all


$msgs = array();

if (strlen($_POST['pass'])<8){
    $msgs[] = 'Password must be at least 8 characters';

 * other checks here
 if (count($msgs)>0){
     echo "Password validation failed:\n";
     die(implode("\n", $msgs));
untested code but pretty straightforward

Post Reply