How to fix: Drupal “user warning: Unknown column…” error

Exact error message:
...
user warning: Unknown column 'page' in 'where clause' query: [function_name] /* [username] : [function_name] */ SELECT n.nid FROM node n WHERE n.type = page AND n.status = 1 ORDER BY n.created DESC LIMIT 0, 5 in /home/user/public_html/path/to.module on line 294.
...

Th query in question:
$result = db_query('SELECT n.nid FROM {node} n WHERE n.type = %s AND n.status = 1 ORDER BY n.created DESC LIMIT 0, %d', variable_get('some_var', NULL), variable_get('another_var', 5));

In my case, it was missing quotes for %s. See below.
$result = db_query('SELECT n.nid FROM {node} n WHERE n.type = "%s" AND n.status = 1 ORDER BY n.created DESC LIMIT 0, %d', variable_get('some_var', NULL), variable_get('another_var', 5));

Drupal developer? Get pro with Pro Drupal Development, Second Edition (Volume 0)

Tagged with 
About sepedatua
I am nothing special, of this I am sure. I am a common man with common thoughts and I’ve led a common life. There are no monuments dedicated to me and my name will soon be forgotten, but I’ve loved another with all my heart and soul, and to me, this has always been enough.

Leave a Reply