i coded this elseif block according to the recommendations on php.net. but the last else: with the colon is generating an error.
then, if i leave off the colon the following { throws an error.
so i then tried making the last else an elseif but then endif; throws an error. very frustrating.
i did try making this a case statement but then the booleans weren't working as expected
PHP Code:
if(($manIdAdd != 0) && (!isValidURL($urlAdd))) { echo 'Id is good but URL is bad, add to error array'; } elseif(($manIdAdd == 0) && (isValidURL($urlAdd))) { echo 'URL is good but ID is bad, add to error array'; } elseif(($manIdAdd != 0) && (isValidURL($urlAdd))) { echo 'Both are good'; echo 'Run Q'; } elseif(($manIdAdd == 0) && (!isValidURL($urlAdd))) { echo 'Both are bad which means user didn\'t intend to add so exit'; } endif;
Just replace the endif with an empty else { }, endif is improper syntax
Code:
if(($manIdAdd != 0) && (!isValidURL($urlAdd))) {
echo 'Id is good but URL is bad, add to error array';
}
elseif(($manIdAdd == 0) && (isValidURL($urlAdd))) {
echo 'URL is good but ID is bad, add to error array';
}
elseif(($manIdAdd != 0) && (isValidURL($urlAdd))) {
echo 'Both are good';
echo 'Run Q';
}
elseif(($manIdAdd == 0) && (!isValidURL($urlAdd))) {
echo 'Both are bad which means user didn\'t intend to add so exit';
}
else { }
this is from php.net though is obviously not correct
PHP Code:
/* Correct Method: */
if($a > $b):
echo $a." is greater than ".$b;
elseif($a == $b): // Note the combination of the words.
echo $a." equals ".$b;
else:
echo $a." is neither greater than or equal to ".$b;
endif;
There are two different PHP conditional syntaxes, one using the more common curly braces approach and the other using the colon and "endif" technique -- but you cannot mix the two together.
Also, you don't need an else{} -- any other valid statement following the closing brace of the last elseif would also terminate the chain.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks