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

Mystic
  • 147
  • 1
  • 14

1 Answers1

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);
Fabien TheSolution
  • 5,055
  • 1
  • 18
  • 30
  • 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 – Mystic Feb 27 '15 at 19:28