Re: IF ELSEIF ELSE??

From: Date: Fri, 03 Aug 2001 22:51:54 +0000
Subject: Re: IF ELSEIF ELSE??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-61183@lists.php.net to get a copy of this message
if (!$HTTP_POST_VARS) exit(); else { if (!$Age) { echo "Please enter your age.<br>\n"; } if (!$Email) { echo "Please enter your email.<br>\n"; } if (!$State) { echo "Please enter your Location.<br>\n";} if ($Age && $Email && $State) echo "Thanks for your submission."; } Your if and else statements used every possibility up, so that last else will never get hit. There are a lot of things you can do better with the above code, but it'll do what you want. For example something you might want to look at the type of data the person is entering, a little validation. I hope that helps. Rick > Whats wrong with this piece of code. Basically, it not doing the last > else statement. > 1. If no form was submitted exit. > 2. If a form was submitted, check for 'empty' strings. > 3. If all is good, echo "xxxxx"; > > Thanks all. > > > > if (!$HTTP_POST_VARS) { exit(); } > elseif ($HTTP_POST_VARS) { > if (!$Age) { echo "Please enter your age.<br>\n"; } if > (!$Email) { echo "Please enter your email.<br>\n"; } > if (!$State) { echo "Please enter your Location.<br>\n";} > } > else > echo "Thanks for your submission.";

« previous php.general (#61183) next »