-1

I have a table with a primary column "MatchId", followed by many other columns.

Unfortunately, I can't seem to get my insert/update query right: Even if I only want to insert an MatchId (Not auto-increment by the way), I get the error Unknown column in 'field list'...

Here is my query:

INSERT INTO `stats` (`MatchId`) VALUES (`123456`);

How do I insert something in this table without getting this error?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Fly
  • 810
  • 2
  • 9
  • 28
  • 1
    show the full schema of your table `stats` – dbinns66 Apr 13 '15 at 19:15
  • 2
    Try VALUES ('123456') (single quotes) in place of VALUES (`123456`) ? – Maximus2012 Apr 13 '15 at 19:15
  • @Fred -ii- I believe that my question is not a duplicate, since I did not explicitely *know* that my problem had to do with backticks (As stated in my original question, I read about backticks etc on stackoverflow, but none of the answers helped me.) – Fly May 19 '15 at 20:51
  • So, why did you accept Barmar's answer then if you feel that it's not a duplicate? – Funk Forty Niner May 19 '15 at 22:00
  • @Fred -ii- As I said, at the time that I created this question I had already tried solutions from other SO questions, but they didnt seem to work for me (Also, I did not know what the problem actually was - Being anout quotes was just a hunch). Barmar answered to my specific problem and made me undrstand why things are like they are. – Fly May 20 '15 at 07:08

2 Answers2

2

You have the wrong types of quotes around the value. Backticks are used around table and column names. To quote a string, use single or double quotes:

INSERT INTO `stats` (`MatchId`) VALUES ('123456');

If it's an integer, you don't need to quote it at all:

INSERT INTO `stats` (`MatchId`) VALUES (123456);

Putting a value in backticks forces it to be treated as a column name, even though it has the syntax of a number. Backticks are the way that MySQL allows you to use column names that have unusual syntax.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Weird, now it works. I don't understand why though: 123456 is an integer, not a string - So why should it be treated like one? – Fly Apr 13 '15 at 19:25
  • 1
    In your original code you were making it a column name by putting it in backticks. – Barmar Apr 13 '15 at 19:27
1

Test it in phpmyadmin the unrecognised field is "123456". Change your SQL and wrap the value in single quotes

Mike Miller
  • 3,071
  • 3
  • 25
  • 32