Michdd Posted October 18, 2008 Share Posted October 18, 2008 I'm trying to insert a variable into a database using this code: mysql_query("INSERT INTO monsters (monster, loc) VALUES($ucTitleString, $loc ) ") or die(mysql_error()); mysql_query("INSERT INTO monsters (spawn, drops) VALUES($spawn, $drops ) ") or die(mysql_error()); mysql_query("INSERT INTO example (hp, exp) VALUES($hp, $exp ) ") or die(mysql_error()); echo "Data Inserted!"; When doing this 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 'name, Location )' at line 2 Quote Link to comment https://forums.phpfreaks.com/topic/128977-solved-inserting-a-variable-into-a-database/ Share on other sites More sharing options...
wildteen88 Posted October 18, 2008 Share Posted October 18, 2008 SQL values need to be warped in quotes. mysql_query("INSERT INTO monsters (monster, loc) VALUES('$ucTitleString', '$loc' ) ") or die(mysql_error()); mysql_query("INSERT INTO monsters (spawn, drops) VALUES('$spawn', '$drops' ) ") or die(mysql_error()); mysql_query("INSERT INTO example (hp, exp) VALUES('$hp', '$exp' ) ") or die(mysql_error()); echo "Data Inserted!"; Quote Link to comment https://forums.phpfreaks.com/topic/128977-solved-inserting-a-variable-into-a-database/#findComment-668664 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.