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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

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

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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)
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

thanks pimp (read it backwards) been a monday on a wednesday all day, actual all week so far :oops:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 :)
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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();
}
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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
Post Reply