Hi DP, On my website I have a SQL query that seems to be causing an error: SELECT content_url,icon_url,content_type,title,shortdesc,desc,rating,date,views,downloadable FROM content WHERE content_id=1 Code (markup): It causes this error:Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'desc,rating,date,views,downloadable FROM content WHERE content_id=1' at line 1' in /home/content/42/9125042/html/contentpage.php:20 Stack trace: #0 /home/content/42/9125042/html/contentpage.php(20): PDO->query('SELECT content_...') #1 {main} thrown in /home/content/42/9125042/html/contentpage.php on line 20Here is the code around it (PHP):What's causing the error in my code? Thanks,-Tony
Is there actually an entry that has content_id of 1? Try spaces ... WHERE content_id = 1 Try quotes, single-quotes or bacticks ... WHERE content_id = '1' If you are selecting most or all of the fields from the table, use * for all: SELECT * FROM content WHERE content_id = 1
$sql = SELECT `content_url`, `icon_url`, `content_type`, `title`, `shortdesc`, `desc`, `rating`, `date`, `views`,`downloadable` FROM `content` WHERE `content_id`='1'"; Code (markup): I've shown how it looks with the backticks - in particular I'd be concerned about the column `desc`, there's no need to have shortened column names - I'd recommend renaming it to description. The next step after making those changes, if the problem persists, is to cut and paste the query into phpMyAdmin and see if you get a more useful error message.