jd307 Posted June 2, 2010 Share Posted June 2, 2010 Hi all, I have searched on the net and through the forums a little for a similar problem, but none of what I have found appear to be the solution to my... what appears to be a rather silly... problem. Any help will be very much appreciated. I have constructed a basic INSERT statement into a MySQL database. $query = "INSERT INTO base (name, gainDef, gainCash, gainHealth, gainAtk, gainPower, price, costs, description, req, level, limit) VALUES ('Name', 'Def', 'Cash', 'Health', 'Attack', 'Power', 'Price', 'Costs', 'Description', 'Requirement', 'Level', 'Limit')"; mysql_query($query) or die(mysql_error()); The VALUES are just test values that I have entered to debug this issue, though are variables normally. Anyhow, executing this SQL statement gives the error of: 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 'limit) VALUES ('Name', 'Def', 'Cash', 'Health', 'Attack', 'Power', 'Price', 'Co' at line 1 If I remove the last two parts (so I remove 'limit' fromthe add list and 'Limit' from VALUES, the SQL statement inserts the data successfully into the database. However with these two in the SQL statement and it produces the error. This, of course leads me to believe that the error is therefore caused by the trying to insert the data into the last column. I cannot figure out why this is the case. Many suggestions for similar errors are because SQL statements have had a comma after the final value, however this does not... so I can't see what is wrong. Any advice is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/203653-sql-insert-statement-probably-something-obvious/ Share on other sites More sharing options...
jd307 Posted June 2, 2010 Author Share Posted June 2, 2010 I have managed to work a solution. The SQL statement now reads as follows: $query = "INSERT INTO `base` (`name`, `gainDef`, `gainCash`, `gainHealth`, `gainAtk`, `gainPower`, `price`, `costs`, `description`, `req`, `level`, `limit`) VALUES ('$name', '$gainDef', '$gainCash', '$gainHealth', '$gainAtk', '$gainPower', '$price', '$costs', '$description', '$req', '$level', '$limit')"; ... and now works. Thanks for those who looked at this problem. Quote Link to comment https://forums.phpfreaks.com/topic/203653-sql-insert-statement-probably-something-obvious/#findComment-1066742 Share on other sites More sharing options...
Karlos94 Posted June 2, 2010 Share Posted June 2, 2010 If in case you are still wondering why it wouldn't work it is because you was using limit which is one of MySQL's attributes, however you did what was necessary to make the query work by wrapping the keyword in the quotes. Quote Link to comment https://forums.phpfreaks.com/topic/203653-sql-insert-statement-probably-something-obvious/#findComment-1066763 Share on other sites More sharing options...
jd307 Posted June 3, 2010 Author Share Posted June 3, 2010 Hi Karlos! Thanks for this... I didn't actually know about the SQL limit command. It explains quite alot... I think I should think about my database columns more in the future. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/203653-sql-insert-statement-probably-something-obvious/#findComment-1066960 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.