Tandem Posted September 26, 2006 Share Posted September 26, 2006 I'm having some trouble with something....Here is some code i wrote just to give an example:[code]<html><head></head><body><?$output = $_POST['output'];if ($output == "nothing") {$output = 0;}if ($output == "something") {echo"<br>Hello";}echo <<<HERE<form method="POST" action="forms.php" name="f"><input type="text" name="output" value=""><input type="submit" name="submit" value="Submit!"></form>HERE;?></body></html>[/code]In this form if you enter the word 'something' into the text input it will echo "Hello". If you enter the word 'nothing' it will set the the variable $output to 0, but then for some reason "Hello" is echoed.Why is this, and what ways are there to stop this? Quote Link to comment Share on other sites More sharing options...
alpine Posted September 26, 2006 Share Posted September 26, 2006 Well, your actually setting the comparasor test to if(0 == "something") - always returning trueThis works, setting to false instead[color=blue]if ($output == "nothing") {$output = false;}if ($output == "something") {echo"< br >Hello";}[/color]But if your purpose with this is to check if formfields are submitted empty or not, use [color=blue]if(!empty($field)){// not empty}else{// empty}[/color] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.