0

I have the following MySQL query:

INSERT INTO ipi_messages (Message_userID, Message_fromName, Message_fromEmail, Message_subject, Message_body) VALUES(`0`, `hope`, `thisworks@gmail.com`, `i hope`, `this works`)

My database schema is:

enter image description here

I cannot, for the life of me, figure out how that error is even possible. Why would MySQL try to find 0 as one of the columns? It is clearly not even in the column declaration piece of the code.

So why am I getting the error Unknown column '0' in 'field list'?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Fillip Peyton
  • 3,637
  • 2
  • 32
  • 60

3 Answers3

8

You need to use regular quotes ' for string values. Backquotes are used to enclose column and table names.

rsanchez
  • 14,467
  • 1
  • 35
  • 46
  • Thanks @rsanchez! I am now getting a new error. Question [here](http://stackoverflow.com/questions/16979633/why-is-this-mysql-syntax-incorrect). – Fillip Peyton Jun 07 '13 at 08:36
0
INSERT INTO ipi_messages (Message_userID, Message_fromName, Message_fromEmail, Message_subject, Message_body) VALUES('0', 'hope', 'thisworks@gmail.com', 'i hope', 'this works')

You need to enclose the string in either single or double quotes.Instead of quotes you used ~(tilt) symbol to enclose the values to insert into the table which caused the error.Because enclosed string in ~ will be considered as the table column name.

웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
0

Could it be that your Message_userID is an integer field? In that case you don't need the quotes ('0' --> 0)

Rob
  • 11,492
  • 14
  • 59
  • 94