0

I just cannot find what is wrong with this simple statement:

$stat_qry = mysql_query("SELECT * FROM stats WHERE group=$galgroup") or die("STATS ERROR: ".mysql_error()); $stat = mysql_fetch_array($stat_qry);

i just get: "STATS 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 'group=1' at line 1"

i cannot get it to work with the 'where' clause, if i remove 'where' it works but just lists everything in the database

3
  • If i got this error, first i would first print the query Commented Feb 27, 2015 at 19:20
  • 2
    Wrap `group` with back ticks because it is a reserved word Commented Feb 27, 2015 at 19:21
  • 1
    Better idea: Don't use reserved words as column/table identifiers. And see about sql-injection, PHP's deprecated mysql API and prepared statements Commented Feb 27, 2015 at 19:25

1 Answer 1

2

GROUP is a reserved word so it needs to be between back tick `` Also, if $galgroup can be a string and not only a number, you need to add quotes arround it :

$stat_qry = mysql_query("SELECT * FROM stats WHERE `group`='$galgroup'") or 
die("STATS ERROR: ".mysql_error()); $stat = mysql_fetch_array($stat_qry);
Sign up to request clarification or add additional context in comments.

1 Comment

i cant believe thats all it took, i spent all day trying to figure this out, recreated my tables, rewrote my code... argh. Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.