MySQL warning about an unknown column that exists

Learning how to find problems with PHP. Now I am trying to solve them, but I do not know how to do it.

I used mysql_error and found:

1054: Unknown column 'o.user_id' in 'on clause' 

Something is wrong with this:

$sql="SELECT o.*, u.user_name, u.email, od.artist_id,cm.nexchange_price

         FROM ".$tableprefix."orders o,".$tableprefix."currency_master cm

        INNER JOIN ".$tableprefix."users u ON o.user_id = u.user_id

        INNER JOIN ".$tableprefix."order_details od ON o.order_id = od.order_id

        WHERE o.order_id = ".GetSQLValueString($orderid,"text")."

         AND o.vorder_currency = cm.vcurrency_code ".$qryopt . " ORDER BY o.order_date DESC";

Does this column exist in the order table ?!

+3
source share
1 answer

You have a comma after "orders o", which means that you are trying to join a table currency_masterwith a table usersinstead of ordersand users. I suppose you wanted to:

$sql="
  SELECT
    o.*, u.user_name, u.email, od.artist_id,cm.nexchange_price
  FROM
    ".$tableprefix."currency_master cm,
    ".$tableprefix."orders o
  INNER JOIN
    ".$tableprefix."users u
  ON
    o.user_id = u.user_id // et cetera"
+6
source

Source: https://habr.com/ru/post/1713003/


All Articles