ibanez270dx Posted July 28, 2006 Share Posted July 28, 2006 Hi, I have a section of a script that needs to check if [month] has been posted, and if it hasn't, assign the default value (date("m")) to $today_month. However, I think this doesn't work because I need some sort of operator in the if( ) thing? [code]if($_POST[month]) { $today_month = "$_POST[month]"; } else { $today_month = date("m"); }[/code]What should I use if I want it to check if there is any value posted for [month] ?Thanks, - Jeff Quote Link to comment https://forums.phpfreaks.com/topic/15912-if-else-problems/ Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 if (isset($_POST['month'])) {is that what you are asking?? Quote Link to comment https://forums.phpfreaks.com/topic/15912-if-else-problems/#findComment-65287 Share on other sites More sharing options...
cmgmyr Posted July 28, 2006 Share Posted July 28, 2006 One way you can do it is: if($_POST[month] > "") Quote Link to comment https://forums.phpfreaks.com/topic/15912-if-else-problems/#findComment-65288 Share on other sites More sharing options...
tomfmason Posted July 28, 2006 Share Posted July 28, 2006 the standard (cleaner) layout for if and else is[code=php:0]if (something == true) { //do something}else{ //do something else}[/code]Now what I would do is this[code=php:0]if (isset($_POST['month'])) { if ($_POST['month'] == "") { //set the month }/*this means that the month was set. You can finish your code*/}//put your form below here[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15912-if-else-problems/#findComment-65293 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 I liked what he showed above, that looks a lot cleaner to me. Quote Link to comment https://forums.phpfreaks.com/topic/15912-if-else-problems/#findComment-65295 Share on other sites More sharing options...
ibanez270dx Posted July 28, 2006 Author Share Posted July 28, 2006 wow, thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/15912-if-else-problems/#findComment-65302 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.