views:

46

answers:

1
mysql_query('SELECT ID 
               FROM documents 
              WHERE (Key="' .$theKey. '" 
                AND Value="' .$theValue. '")');

Isn’t this right? Also tried with a semicolon at the end of the string, but no luck. Driving me crazy, PHP keeps spitting out:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Key="title" AND Value="Lollercoaster")' at line 1

It works if I remove the WHERE clause

+4  A: 

Key is a reserved key word. Quote it with ` and it works:

'SELECT ID FROM documents WHERE (`Key`="' .$theKey. '" AND Value="' .$theValue. '")'
Gumbo
Fantastic. Thought I was being oblivious. Thanks for saving me from humiliation.
Not Rick Astley