导致此“MySQL错误#1054 - 未知列”错误的原因是什么?

时间:2011-02-25 17:38:52

标签: php mysql sql mysql-error-1054

我对这个MySQL查询有点问题。我已经使用过我在另一个问题中看到过的建议,但仍然无效......

这是代码

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

哪个给出了

  

无效的SQL查询
  'where子句'中的未知列'phcdl_files.file_author'(MySQL错误号; 1054)

3 个答案:

答案 0 :(得分:5)

这意味着表phcdl_files中不存在列file_author。你可能想要

$kernel->db->query( "UPDATE " . TABLE_PREFIX . "users SET total_downs = total_downs + 1 WHERE file_author = " . $file['file_author'] );
编辑:请参阅上面Byron Whitlock的评论。您通常不希望将变量直接插入SQL查询字符串。

答案 1 :(得分:1)

如果phcdl_files是表的名称,则需要在查询中包含该表,并在TABLE_PREFIXusers中表示它与{{1}}中的行之间的某种关系想要更新。

答案 2 :(得分:1)

phcdl_filesfile_author在哪里?

 "UPDATE `" . TABLE_PREFIX . "users` 
          SET `total_downs` = `total_downs` + 1 
          WHERE `user`.`file_author` = " . $file['file_author']

和$ file ['file_author']应来自phcdl_files表

相关问题