Question

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)

Was it helpful?

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.

OTHER TIPS

If phcdl_files is the name of a table, you need to include that table in your query, and express some relationship between it and the rows in TABLE_PREFIXusers that you want to update.

where is phcdl_files.file_author?

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

and $file['file_author'] should come from phcdl_files table

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top