SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple if() statement driving me nuts!

    If someone could help, I'd be really grateful!!

    I don't get what's wrong with this:

    PHP Code:
    if(($type == NULL) || ($price == NULL)){
    echo (
    "Please select both a toy type and an price range");
    include 
    'search_form.php';
    exit(); } 
    Thank you very much

  2. #2
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly is wrong with it? What is it doing? what do you expect it to do?

    I hope those variables are coming out of the $_POST superglobal, and you're not relying on register globals?

    Also if they're coming from a form, if the field is empty, it'll probably come as an empty string, not null.

  3. #3
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dev,

    Thanks for the reply

    Quote Originally Posted by devbanana
    I hope those variables are coming out of the $_POST superglobal, and you're not relying on register globals?
    No, I'm getting the variables from $_POST ok. In fact I'm printing them just above the if() statement and they're printing as NULL NULL.

    At the moment, I'm just trying to get that echo() statement to print out, but all I'm getting is a blank screen.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Finland
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if they are printing NULL then you must compare them to string 'NULL', not null.

    if(($type == 'NULL') || ($price == 'NULL')){

  5. #5
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you show the code you use to print the variables above that if statement?

    Also, I don't know if this has anything to do with it, but usually I use a lowercase null.

  6. #6
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JaskaS
    if they are printing NULL then you must compare them to string 'NULL', not null.

    if(($type == 'NULL') || ($price == 'NULL')){
    Ahhh, that will be it - thanks JaskaS

    Thanks everyone for your time.

  7. #7
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's odd though. They shouldn't be that way unless you explicitly set the string to the string NULL, and not the PHP null value, because PHP would not do something like this.

    I would say this is very inappropriate, and you should check your code to see why this is happening.


Bookmarks

Posting Permissions

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