Search code examples
phpmysqlsqlmysql-error-1054

MySQL warning of Unknown column that exists


Having found out how to find PHP problems. I am now trying to solve them, but I have no clue on this one.

I made use of mysql_error and I have found:

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

Is there something 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";

That column exists in the orders table?!


Solution

  • You have a comma after "orders o,", which means that you are trying to join the currency_master table with the users table, instead of orders and users. I suppose you wanted to have:

    $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"