Results 1 to 6 of 6

Thread: if statement not working

  1. #1
    Join Date
    Jan 2010
    Posts
    48
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default if statement not working

    I have a site which I need to display a table based on a boolean in my database, basiacally if the product has accessories or not.

    PHP Code:
    $sql "SELECT accessory FROM ver_pro where pID='1' AND prCode = '1000107'";
    $result mysql_query($sql);
    $query_data mysql_fetch_assoc($result);
    if (
    $query_data == 1){
    //display code
    }
    else {
    echo 
    'fail';

    However all I get is the fail. I have double checked the SQL and phpmyadmin beings back Accessory as 1 which is what I expected, but I don't seem to be able to show the extra code based on this boolean... and it just lags the page out a lot and displays a blank page or a 'cannot display page' if the code is wrong, no errors even and errors are turned on.

    Any help would be awesome,

    Thanks in advance

    Aravona

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It never should be equal to one. It will be equal to data. You could use !==FALSE.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    [spam removed]
    Last edited by djr33; 07-22-2010 at 01:48 PM.

  4. #4
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Could it be that in your string for the query your 'where' isn't WHERE? DJR33 - is that correct that it should always be in uppercase or it won't read it right?

  5. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    No, the where doesn't need to be capitalized or at least no in DBs I've worked with. Air Jordans haha that's some nice random spam placement.

    I assume djr's solution fixed the problem.
    Corrections to my coding/thoughts welcome.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It doesn't need to be uppercase, though I find it easier to read and thus more likely to work (less chance of a typo, etc). Same with the `tablename` with the backticks. It's not required, but in some cases that one actually can matter. Usually it's not important, but I always use it just to have consistent code.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •