Search code examples
phpmysqlsqlmysql-error-1054

What is causing this "MySQL error #1054 - Unknown column" error?


I'm having a little problem with this MySQL query. I've already used an suggestion I've seen in another question but still doesn't work....

Here's the code

$kernel->db->query( "UPDATE `" . TABLE_PREFIX . "users` 
                        SET `total_downs` = `total_downs` + 1 
                      WHERE `phcdl_files`.`file_author` = " . $file['file_author'] );

Which gives

Invalid SQL Query
Unknown column 'phcdl_files.file_author' in 'where clause' (MySQL error no; 1054)


Solution

  • That means that the column file_author doesn't exist in the table phcdl_files. You probably want

    $kernel->db->query( "UPDATE " . TABLE_PREFIX . "users SET total_downs = total_downs + 1 WHERE file_author = " . $file['file_author'] );
    

    EDIT: please see the comment by Byron Whitlock above. You generally don't want to insert a variable directly into a SQL query string.