galvin Posted January 27, 2010 Share Posted January 27, 2010 The code below keeps giving me "Database query failed: 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 'show = 'YES' ORDER BY lastname' at line 3" Can anyone tell what's wrong? The code worked fine until I added line 3 (i.e. WHERE show = 'YES'). There is definitely a field called "show" in the quarterbacks table and there are plenty of rows that have "YES" in the column. Anyone? $sql = "SELECT firstname, lastname, playerid, team, teamid, injured, FROM quarterbacks WHERE show = 'YES' ORDER BY lastname"; Quote Link to comment https://forums.phpfreaks.com/topic/189932-sql-syntax/ Share on other sites More sharing options...
galvin Posted January 27, 2010 Author Share Posted January 27, 2010 Figured out that I needed "backticks" around 'show' and now it works fine. Now, can anyone explain why backticks are need in that situation? Quote Link to comment https://forums.phpfreaks.com/topic/189932-sql-syntax/#findComment-1002169 Share on other sites More sharing options...
PFMaBiSmAd Posted January 27, 2010 Share Posted January 27, 2010 Back-ticks are used when an identifier (database, table, or column name) requires special handling. In your case, show is a reserved keyword - http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Quote Link to comment https://forums.phpfreaks.com/topic/189932-sql-syntax/#findComment-1002183 Share on other sites More sharing options...
galvin Posted January 27, 2010 Author Share Posted January 27, 2010 Dammit, disappointed in myself for not thinking of that possibility. Anyway, thanks so much, you guys are geniuses. Quote Link to comment https://forums.phpfreaks.com/topic/189932-sql-syntax/#findComment-1002184 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.