Re: if elseif elseif elseif....
| From: | Al | Date: | Thu, 05 Mar 2009 12:23:36 +0000 |
| Subject: | Re: if elseif elseif elseif.... | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-289359@lists.php.net to get a copy of this message | ||
Al wrote:
PJ wrote:$obligatoryFieldNotPresent=null; foreach($_POST, as $value) {PJ wrote:finally found the problem... wrong names for string and this is what now verifies correctly.... if (strlen($_POST["titleIN"]) == 0 ) {Daniel Brown wrote:That's where the problem lies... the algorhythm is if any one of a series is empty, then it's an error, but if they are all ls then we go on... So the last one should show up as "0"... I tried else $obligatoryFieldNotPresent = 0; but that doesn't want to work. I tried echo $obligatoryFieldNotPresent; just get a blank page... I can't figure out how to determine if anything is in the String... perhaps I should be checking for null elseif ($obligatoryFiledNotPresent == "") {On Wed, Mar 4, 2009 at 17:51, PJ <af.gourmet@videotron.ca> wrote:Are you certain you only wanted a single equal operator in the last elseif() condition? Further, are you sure it should even be an elseif() and not a straight else?}elseif ($obligatoryFieldNotPresent = 1) { $obligatoryFieldNotPresent = 0;$obligatoryFieldNotPresent = 0; }I tried that too, but same result...$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;But now I have to figure out the workflow and see why it is not going the right way... wonder where I got some of this stuff...
if(!empty($value)continue;
$obligatoryFieldNotPresent=true;
}
Sorry, I was in too big a hurry...
$obligatoryFieldNotPresent=null;
foreach($_POST as $value)
{
if(!empty($value))continue;
$obligatoryFieldNotPresent=true;
}
And if you want to know which field(s) failed:
$obligatoryFieldNotPresent=array();
foreach($_POST as $key=>$value)
{
if(!empty($value))continue;
$obligatoryFieldNotPresent[]=$key;
}