chocopi Posted May 26, 2007 Share Posted May 26, 2007 When i try to use this code: <?php $query = @mysql_query("SELECT id,name,desc,hp,item FROM enemies WHERE id>0 ORDER BY rand() LIMIT 1"); $row = @mysql_fetch_assoc($query) or die(mysql_error()); $enemy_id = $row['id']; $enemy_name = $row['name']; $enemy_desc = $row['desc']; $enemy_hp = $row['hp']; $enemy_item = $row['item']; ?> I get this 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 'desc,hp,item FROM enemies WHERE id>0 ORDER BY rand() LIMIT 1' a Quote Link to comment https://forums.phpfreaks.com/topic/53066-solved-error-in-this/ Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 try @mysql_query("SELECT id,name,`desc`,hp,item FROM enemies WHERE `id`>0 ORDER BY rand() LIMIT 1"); desc isn't a valid field name Quote Link to comment https://forums.phpfreaks.com/topic/53066-solved-error-in-this/#findComment-262149 Share on other sites More sharing options...
chocopi Posted May 26, 2007 Author Share Posted May 26, 2007 Cheers thats sorted it, just for future reference, by using the ' ' what has it done ? ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/53066-solved-error-in-this/#findComment-262151 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 the `` (backticks) allow you to use "illegal" words, its not recommended you should really change the name of the field! Quote Link to comment https://forums.phpfreaks.com/topic/53066-solved-error-in-this/#findComment-262160 Share on other sites More sharing options...
chocopi Posted May 26, 2007 Author Share Posted May 26, 2007 oh ok, Cheers Quote Link to comment https://forums.phpfreaks.com/topic/53066-solved-error-in-this/#findComment-262164 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.