Jump to content


Photo

If... ...else problems


  • Please log in to reply
5 replies to this topic

#1 ibanez270dx

ibanez270dx
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 28 July 2006 - 05:40 PM

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?

if($_POST[month])
	{
	 $today_month = "$_POST[month]";
	}
      else
             {
              $today_month = date("m");
             }

What should I use if I want it to check if there is any value posted for [month] ?

Thanks,
- Jeff

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 05:44 PM

if (isset($_POST['month'])) {
is that what you are asking??

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 28 July 2006 - 05:45 PM

One way you can do it is: if($_POST[month] > "")

#4 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 28 July 2006 - 05:50 PM

the standard (cleaner) layout for if and else is

if (something == true) {
    //do something
}else{
    //do something else
}

Now what I would do is this


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
   

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 05:52 PM

I liked what he showed above, that looks a lot cleaner to me.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#6 ibanez270dx

ibanez270dx
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 28 July 2006 - 05:57 PM

wow, thanks everyone!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users