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
robster
Forum Contributor
Posts: 360 Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia
Post
by robster » Wed Jun 08, 2005 8:28 am
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
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Wed Jun 08, 2005 9:00 am
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.
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Wed Jun 08, 2005 9:24 am
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)
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Jun 08, 2005 9:33 am
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.
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Wed Jun 08, 2005 11:34 am
thanks pimp (read it backwards) been a monday on a wednesday all day, actual all week so far
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Jun 08, 2005 1:16 pm
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
robster
Forum Contributor
Posts: 360 Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia
Post
by robster » Thu Jun 09, 2005 7:15 am
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 » Thu Jun 09, 2005 8:56 am
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();
}
robster
Forum Contributor
Posts: 360 Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia
Post
by robster » Thu Jun 09, 2005 6:21 pm
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