Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default SQL error help needed.

    Hi,

    I'm getting an error from an sql query that i can't seem to fix.
    This error is in a mod i was porting from OSC, and up until recently this section of the port was complete, but since my host upgraded there php and MySQL version it is showing the error.

    The error message reported by ZC is:

    1054 Unknown column 'fg.products_id' in 'on clause'
    in:
    [select fg.*, p.products_id, pd.products_name from free_gifts fg, products p LEFT JOIN products_description pd ON (pd.products_id=fg.products_id) WHERE pd.language_id = '1' AND p.products_id = fg.products_id ORDER BY fg.threshold ASC]


    The query being made is:

    $gift = $db->Execute("select fg.*, p.products_id, pd.products_name from " . TABLE_CARROT . " fg, products p LEFT JOIN products_description pd ON (pd.products_id=fg.products_id)
    WHERE pd.language_id = '" . (int)$_SESSION['languages_id'] . "' AND p.products_id = fg.products_id ORDER BY fg.threshold ASC");
    while (!$gift->EOF) {

    Site is running zen cart version 1.3.7
    DB patch level 1.3.7
    PHP version 5.1.2
    SQL verion 5.0.18

    Any suggestions on a fix for this?

    Thanks in advance
    Steve

  2. #2
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: SQL error help needed.

    It means that your "free_gifts" table, or whatever the name denoted by TABLE_CARROTS is, doesn't have a products_id field in it, but you're telling the SQL to use the products_id field when matching records between the free-gifts table and your product-descriptions table.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default Re: SQL error help needed.

    Quote Originally Posted by DrByte View Post
    It means that your "free_gifts" table, or whatever the name denoted by TABLE_CARROTS is, doesn't have a products_id field in it, but you're telling the SQL to use the products_id field when matching records between the free-gifts table and your product-descriptions table.
    That's the assumption most would make from the error message, except it does have that field.
    The "free_gifts" table has three fields in it. gift_id, threshold, and products_id.

    I'm stumped to be honest, and i can only assume it's related to the change to sql 5.

    Any other ideas?

    Thanks

    Steve

  4. #4
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: SQL error help needed.

    Actually, yes, it does have everything to do with MySQL5 ... and poorly formed queries.
    MySQL 5 enforces strict syntax correctness by default.

    Thus, your left join between 2 tables that are *not* your fg table will trigger the error message.
    Quote Originally Posted by strelitzia View Post
    1054 Unknown column 'fg.products_id' in 'on clause'
    in:
    [select fg.*, p.products_id, pd.products_name from free_gifts fg, products p LEFT JOIN products_description pd ON (pd.products_id=fg.products_id) WHERE pd.language_id = '1' AND p.products_id = fg.products_id ORDER BY fg.threshold ASC]
    You'll need to rewrite the query so that your "ON" clause criteria contains values that are available in the join. (ie: right now you're joining "p" and "pd" tables, but trying to join them on "fg" and "pd")
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. sql syntax error 1064 - HELP NEEDED - Master Password
    By mydesignerstudio in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 20 Jul 2009, 04:22 PM
  2. SQL JOIN (help needed)
    By stagebrace in forum General Questions
    Replies: 0
    Last Post: 17 Apr 2009, 11:26 PM
  3. Help about error 1146 Table.. SQL database Help
    By falerohydro in forum General Questions
    Replies: 2
    Last Post: 25 Feb 2008, 08:29 AM
  4. SQL File Error - URGENT HELP NEEDED PLEASE
    By Adds in forum General Questions
    Replies: 13
    Last Post: 29 Oct 2007, 08:16 AM
  5. A little SQL help needed
    By rstevenson in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 10 Apr 2007, 03:52 AM

Posting Permissions

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