Re: if elseif elseif elseif....

From: Date: Thu, 05 Mar 2009 01:11:56 +0000
Subject: Re: if elseif elseif elseif....
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-289319@lists.php.net to get a copy of this message
finally found the problem... wrong names for string and this is what now verifies correctly.... if (strlen($_POST["titleIN"]) == 0 ) {
            $obligatoryFieldNotPresent = 1;
    }
    elseif (strlen($_POST["first_nameIN"]) == 0 ) {
            $obligatoryFieldNotPresent = 1;
    }
    elseif (strlen($_POST["publisherIN"]) == 0 ) {
            $obligatoryFieldNotPresent = 1;
    }
    elseif (strlen($_POST["copyrightIN"]) == "" ) {
            $obligatoryFieldNotPresent = 1;
    }
    elseif (strlen($_POST["ISBNIN"]) == 0 ) {
            $obligatoryFieldNotPresent = 1;
    }
    elseif (strlen($_POST["languageIN"]) == 0 ) {
            $obligatoryFieldNotPresent = 1;
    }
    elseif (!empty($_POST['categoriesIN'])) {
            $obligatoryFieldNotPresent = 0;
I'd suggest something slightly different. $errors = array(); if (empty($_POST['title'])) { $errors[] = 'title'; } if (empty($_POST['first_nameIN'])) { $errors[] = 'first_nameIN'; } ... # If we found any errors, show a message! if (!empty($errors)) { echo "You forgot to fill in these fields:<br/>"; echo implode(',', $errors) . "<br/>"; } So your user knows what they missed. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#289319) next »