SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    WHERE show = 'Y' gives an error (was "Simple SQL Problem")

    First off, I'm using MYSQL Version 4.0.25, though I really don't think MySQL is the problem.

    The query is so simple it's beyond my comperhension why it's not working. I think I've been coding for to many hours and can no longer see the obvious.

    Any ways, the Query is:

    SELECT * FROM section WHERE show = 'Y' ORDER BY section

    The table structure is:
    Code:
    CREATE TABLE `section` (
    `ID` int(11) NOT NULL auto_increment,
    `section` varchar(64) NOT NULL default '',
    `show` enum('Y','N') NOT NULL default 'Y',
    PRIMARY KEY (`ID`)
    )
    The php code is:
    PHP Code:
    $sql1 "SELECT * 
    FROM section
    WHERE show = 'Y'
    ORDER BY section"
    ;
    $result1 mysql_query($sql1);
    if (!
    $result1) {
    echo 
    "RESULT1 ERROR: ".mysql_error($result1)."<br>SQL1 = $sql1<br>\n";

    This returns the error:

    Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /home/path to/public_html/test.php on line 9
    RESULT1 ERROR:
    SQL1 = SELECT * FROM section WHERE show = 'Y' ORDER BY section

    Interestingly, if I remove the WHERE statement, the query works fine. I, of course, get results with sections who's show equal 'Y'.

    Please someone explain to me why this isn't working?

    Thanks, Sandra

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The word SHOW is on the reserved words list. Rename your column to something that isn't on the reserved word list and you won't have this problem.

  3. #3
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was quite shocked by your answer, only because I had looked it up in my non-db specpic SQL manual. It doesn't list show as being reserved. Just now, I went mysql.com and sure enough, you are right. Many thanks for getting me on the right track.

    -- Sandra

  4. #4
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    always look up reserved words on the database you are using rather than a non-db sql manual. different databases have different reserved words.

    in fact mysql even has some reserved words that they actually let you use. (no idea why they would do this, I think they are making it retroactive i.e. whereas you could use them in the past they are now on the list but are letting you use them because you could in the past.)


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
  •