Hyperactive Inc.
Please Login or Register

Knowledgebase

How To Fix: Error Message - 1054 - Unknown column 'p.products_id' in 'on clause' In osCommerce

If your getting this error it is due to the fact that your server is running PHP 5 or later, and you are running a pre-December 2006 version of osCommerce, which is not compatible with PHP5+. The fix for this is very simple, even if you dont know any PHP programming yourself by following this guide.

I wont go into to much technical detail here, as that would only server to confuse you. I will say that Mysql changed the way it handled "left Join" statements in Mysqp version 5. The problem cause the error in question.

Also, if your store is not stock osCommerce, the line numbers given in this example may not be exact, and you may need to use a search utility or Notepad in windows to find the exact lines you need to modify.

1. Lets start with your Index.php file. At or around line 170-190 you will see the following code:

// We are asked to show only a specific category
        $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price,  p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "'";

2. Notice the words "Left Join" in the code above? start reading backwards from the left joins until you find the "from" statement, as here below;

from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join

3. Starting with Mysql 5 you need to add open and closed parenthasis to this code to make it compatible. For instance, to correct the code above it should look like this;

from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c) left join

4. So now you understand that from and left joins are held together by an opening and closing parenthasis. The same hold true for code that contains more than one left join. For instance, the next section of code in your index.php which looks like this;

// We show them all
        $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price,  p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";

Notice how this code from your stores index.php file contains two left joins? This changes things a bit, since we now must use TWO opening parenthasis after the "from" statement, and one parenthasis next to each left join.

code before fix;

from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join

and code after fix;

from ((" . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p) left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c) left join

==============================================================

Now you should be able to correct any files in your store to make them Mysql 5 compatible. Just use a file searching tool to search through all your oscommerce files for "left join", then open those files and edit them aaccording to this tutorial. The two main files which will cause you problems and will keep your store from running until you fix it are the /catalog/index.php file and the /catalog/advanced_search_result.php

 



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article


Language:

Quick Navigation

Client Login

Email

Password

Remember Me

Search