Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts

    IF, AND, OR statements

    Is there any reason for why this isn't working? It should be

    IF contype is equal to Question, AND question2 is blank, OR answer1 is blank, OR answer2 is blank, etc.

    I need to see if contype is question, and need to see if any fields are blank. But it isn't accepting it.

    PHP Code:
    if (($contype == 'question') && $question2 == '' || $answer1 == '' || $answer2 == '' || $answer3 == '' || $answer4 == '' || $answer5 == '' || $answer6 == '' || $answer7 == '' || $answer8 == '') { 
    Last edited by myfayt; 12-13-2010 at 10:08 PM.

  • #2
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Might be a long shot but have you tried this?

    PHP Code:
    if (($contype == 'question') && ($question2 == '' || $answer1 == '' || $answer2 == '' || $answer3 == '' || $answer4 == '' || $answer5 == '' || $answer6 == '' || $answer7 == '' || $answer8 == '')) { 
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #3
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    I think this is what you meant to do:
    PHP Code:
    if (($contype == 'question' && $question2 == '') || $answer1 == '' || $answer2 == '' || $answer3 == '' || $answer4 == '' || $answer5 == '' || $answer6 == '' || $answer7 == '' || $answer8 == '') { 
    Your parenthesis closed before the && part rather than after that particular check...

    Unless DJCMBear's string is correct in that every case should have contype equal to "question". It's hard to determine that based on what you wrote though.

    Edit: Hmm, now that I re-read it with DJCMBear's method in mind I think that he hit what you are after.
    Last edited by Rowsdower!; 12-13-2010 at 07:38 PM.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    That worked, thanks guys


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •