programguru Posted March 6, 2007 Share Posted March 6, 2007 if ($submit == 'true' && $name == '' || $email == '' || $msg == '') { $nomsgerr = "<span class=\"msg\">Please enter your information<br />in all fields marked with *.</span>"; } The issue I am having is my Submit button seems to display my err message by default when my page loads. I figured $submit == 'true' would create the err ONLY of the submit button was pressed, but it does not seem to be working! All my other code (not posted) with submit is working fine, but I dont want $nomsgerr to display if the submit button is not pressed. Does anyone know a workaround? Link to comment https://forums.phpfreaks.com/topic/41413-submit-true-losing-my-mind-any-ideas-as-a-workaround/ Share on other sites More sharing options...
iceman400 Posted March 6, 2007 Share Posted March 6, 2007 this is gonna sound silly, but i've had problems like that in the past and when i added extra () around the OR statements, problem was solved. but that might just be my system. Link to comment https://forums.phpfreaks.com/topic/41413-submit-true-losing-my-mind-any-ideas-as-a-workaround/#findComment-200605 Share on other sites More sharing options...
Greaser9780 Posted March 6, 2007 Share Posted March 6, 2007 Such as: if ($submit == 'true' && ($name == '' || $email == '' || $msg == '')) { $nomsgerr = "<span class=\"msg\">Please enter your information<br />in all fields marked with *.</span>"; } Link to comment https://forums.phpfreaks.com/topic/41413-submit-true-losing-my-mind-any-ideas-as-a-workaround/#findComment-200607 Share on other sites More sharing options...
programguru Posted March 6, 2007 Author Share Posted March 6, 2007 Greaser, Im not sure why, but I had to remove the == 'true' to make it work. Thanks for the tip its working now! if ($submit && ($name == '' || $email == '' || $msg == '')) { $nomsgerr = "<span class=\"msg\">Please enter your information<br />in all fields marked with *.</span>"; } Link to comment https://forums.phpfreaks.com/topic/41413-submit-true-losing-my-mind-any-ideas-as-a-workaround/#findComment-200616 Share on other sites More sharing options...
Greaser9780 Posted March 6, 2007 Share Posted March 6, 2007 probably because submit had to be executed if it called this script. Link to comment https://forums.phpfreaks.com/topic/41413-submit-true-losing-my-mind-any-ideas-as-a-workaround/#findComment-200619 Share on other sites More sharing options...
mjlogan Posted March 6, 2007 Share Posted March 6, 2007 A. !( 1 || 0 ) ANSWER: 0 B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR) C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful) remember those BRACKETS Link to comment https://forums.phpfreaks.com/topic/41413-submit-true-losing-my-mind-any-ideas-as-a-workaround/#findComment-200637 Share on other sites More sharing options...
paul2463 Posted March 6, 2007 Share Posted March 6, 2007 in PHP everything that exists is "true" unless it is declared as "false" or "NULL" so if $submit="Hello"; //means $submit is not an empty string and exists in a true state // so if($submit) // evaluates to true because it exists and is not false or NULL $submit = false; //means $submit exists in a false state // so if($submit) //evaluates to false $submit = NULL; //means $submit doesnt exist // so if($submit) //evaluates to false thats the way I look at it anyway Link to comment https://forums.phpfreaks.com/topic/41413-submit-true-losing-my-mind-any-ideas-as-a-workaround/#findComment-200659 Share on other sites More sharing options...
programguru Posted March 6, 2007 Author Share Posted March 6, 2007 Well, This has been very educational. Now I need to find a new problem to solve! Link to comment https://forums.phpfreaks.com/topic/41413-submit-true-losing-my-mind-any-ideas-as-a-workaround/#findComment-200664 Share on other sites More sharing options...
programguru Posted March 6, 2007 Author Share Posted March 6, 2007 Paul, Maybe I am just way too tired but you said: in PHP everything that exists is "true" unless it is declared as "false" or "NULL" Then if($submit) //evaluates to false It appears this would evaluate to true? What you say? Am I in la la land? Link to comment https://forums.phpfreaks.com/topic/41413-submit-true-losing-my-mind-any-ideas-as-a-workaround/#findComment-200666 Share on other sites More sharing options...
paul2463 Posted March 6, 2007 Share Posted March 6, 2007 because just above that line I had the line i changed thevalue of $submit here is the same information but with the variable names changed as well to make it easier to read $var1="Hello"; //means $var1 is not an empty string and exists in a true state // so if($var1) // evaluates to true because it exists and is not false or NULL $var2 = false; //means $var2 exists in a false state // so if($var2) //evaluates to false $var3 = NULL; //means $var3 doesnt exist // so if($var3) //evaluates to false Link to comment https://forums.phpfreaks.com/topic/41413-submit-true-losing-my-mind-any-ideas-as-a-workaround/#findComment-200752 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.