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? Link to comment https://forums.phpfreaks.com/topic/22110-if-help/ 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] Link to comment https://forums.phpfreaks.com/topic/22110-if-help/#findComment-99003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.