I have a pretty simple table with 5 columns:
key, datetime, title, body, image
The user selects a title from a dropdown box and a form is populated with the datetime, body, and image. When I try to select by key nothing happens. However, If I select by title it works.
doesn't work:
SELECT body FROM myTable WHERE key='140'
works:
SELECT body FROM myTable W开发者_JS百科HERE title='hello world'
I've tried this by typing the query directly into phpMyAdmin and it gives me an error saying there is a problem at 'key='140''.
key
is a reserved word. You should surround it with backticks:
SELECT body FROM myTable WHERE `key`='140'
Because most likely key is numeric
try:
SELECT body FROM myTable WHERE key=140
without the quotes
Or possibly a combination of the two answers already given. A numeric key with a reserved word:
SELECT body FROM myTable WHERE `key`=140
Because key is a reserve word on SQL.
you can use
SELECT body FROM myTable WHERE [key]='140'
精彩评论