Darkranger85 Posted January 24, 2012 Share Posted January 24, 2012 I'm trying to brush up on connecting and interacting with a database and in the tutorial I was directed to write the following: <?php //Include Connection// require 'connect.inc.php'; $query = "SELECT 'food', 'calories' FROM 'food' ORDER BY 'id'"; if($query_run = mysql_query($query)){ echo 'Query was successful!'; } else { echo mysql_error(); } ?> But, I get the following error: "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 ''food' ORDER BY 'id'' at line 1" Whereas he gets "Query was successful." I went over mind and compared it to his practically letter by letter and I can't figure it out. Anyone mind pointing me in the right direction? lol Quote Link to comment https://forums.phpfreaks.com/topic/255705-mysql-syntax-error/ Share on other sites More sharing options...
Pikachu2000 Posted January 24, 2012 Share Posted January 24, 2012 Unless the database/table/field name is a MySQL reserved word, it doesn't need to be enclosed in anything. And then if it is a reserved word, you'd use `backticks`, not 'single quotes'. Quote Link to comment https://forums.phpfreaks.com/topic/255705-mysql-syntax-error/#findComment-1310823 Share on other sites More sharing options...
Darkranger85 Posted January 25, 2012 Author Share Posted January 25, 2012 Thank you pikachu! You guys are really knowledgeable! Quote Link to comment https://forums.phpfreaks.com/topic/255705-mysql-syntax-error/#findComment-1310911 Share on other sites More sharing options...
Pikachu2000 Posted January 25, 2012 Share Posted January 25, 2012 That's why we get paid the big bucks. Or nothing. Whichever is less . . . Quote Link to comment https://forums.phpfreaks.com/topic/255705-mysql-syntax-error/#findComment-1310912 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.