Jump to content

SQL Insert Statement - Probably something obvious


jd307

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.