Page 1 of 1

Syntax question (if this or that or the other or something)

Posted: Wed Jun 08, 2005 8:28 am
by robster
Hi there,

I know I should be shot for this, and I've got it correct in the past, but I'm losing it, as searching for 'or' in google doesn't work (so I can't get a result for PHP or operator, and it seems to ignore || also.

So the question is, could somebody please correct this syntax for me (cringe!) :|

Code: Select all

if (($get_bday_day == "") || ($get_bday_month == "") || ($get_bday_year == ""))
Thanks SO much, I've tried many variations, but I'm sure my bracketing () is all wrong.

Rob

Posted: Wed Jun 08, 2005 9:00 am
by phpScott
to help me at least you may want to rephrase your question to pseduo code(it might also help you get to where you need to go)

As I see it if any of your three varaibles are blank then your if statement fails.

I take it this isn't what you want though.

Posted: Wed Jun 08, 2005 9:24 am
by shiznatix
i dont see any syntax problems in that although the () around your conditions arn't nessicary im pretty sure that you can still use them (like with echo)

Posted: Wed Jun 08, 2005 9:33 am
by JayBird
phpScott wrote:As I see it if any of your three varaibles are blank then your if statement fails.
The statement equates to true for all cases unless all the variables are NOT empty.

Posted: Wed Jun 08, 2005 11:34 am
by phpScott
thanks pimp (read it backwards) been a monday on a wednesday all day, actual all week so far :oops:

Posted: Wed Jun 08, 2005 1:16 pm
by John Cartwright
phpScott wrote: As I see it if any of your three varaibles are blank then your if statement fails.
I often confused the || ANd && on mondays too :)

Posted: Thu Jun 09, 2005 7:15 am
by robster
Thanks for the replies, basically the code is a check to see if the user has filled in their birthdate in the user registration page I'm creating.

It's designed to ask:

Code: Select all

if no birthday entered OR if no month entered OR if no year entered

Then spit the dummy...

Else all's well...
Hope that helps, and thanks again for the replies.
I guess something else must be wrong with my code if that is fine.

I'll dig deeper.

Posted: Thu Jun 09, 2005 8:56 am
by timvw
if no birthday entered OR if no month entered OR if no year entered

Then spit the dummy...

Else all's well...

Code: Select all

if (!isset($_POST['birthday']) || !isset($_POST['month']) || !isset($_POST['year']))
{
  spit();
}
else
{
  allwell();
}
I usually end up writing as follows:

Code: Select all

if (!isset($_POST['birthday']))
{
  spit('birthday');
}

if (!isset($_POST['year']))
{
  spit('year');
}

if (!$nospitting)
{
  allwell();
}

Posted: Thu Jun 09, 2005 6:21 pm
by robster
That's lovely, I really need to up my knowlege on variable passing. The issit function looks great, time to do some research.

Thanks so much, you've inspired me (and answered my question) :)


Rob