co.ador Posted July 26, 2009 Share Posted July 26, 2009 I have a query error Error in query: SELECT rating , COUNT(*) AS rating_counts FROM rating WHERE item_name = GROUP BY rating. 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 'GROUP BY rating' at line 2 the query goes like this $query ="SELECT rating , COUNT(*) AS rating_counts FROM rating WHERE item_name = $shoename GROUP BY rating"; Quote Link to comment https://forums.phpfreaks.com/topic/167538-help-with-a-query-slq-syntax-error/ Share on other sites More sharing options...
celsoendo Posted July 27, 2009 Share Posted July 27, 2009 If you see the error message you'll see that variable $shoename is empty. By the way, if the column is a char/varchar column you must enclose the variable with quotes. $query ="SELECT rating , COUNT(*) AS rating_counts FROM rating WHERE item_name = '$shoename' GROUP BY rating"; With this, even if the variable is empty the query will not generate an error. Quote Link to comment https://forums.phpfreaks.com/topic/167538-help-with-a-query-slq-syntax-error/#findComment-883689 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.