user2682169
user2682169

Reputation: 51

mysql 1054, unknown column, but I'm not specifying a column

I have a basic customer table. The columns are:

FirstName   LastName   Organization   PhoneNumber   City   State   Zip   ID

ID is an autoincremented value.

I want to insert a new record into the table so I issue this command:

INSERT INTO CustomerTable (FirstName, LastName, Organization, PhoneNumber, City, State, Zip) VALUES (John, Doe, None, 5555555555, Nowhere, NY, 12345);

However, when I issue this statement, I get this error:

ERROR 1054 (42s22): Unknown column 'John' in 'field list'

Why am I getting this error? 'John' is a value to go in a column, not an actual column itself.

Thanks in advance for any help!

Upvotes: 0

Views: 426

Answers (3)

Hanky Panky
Hanky Panky

Reputation: 46900

Put the string values in quotes. Outside quotes those strings will be treated as column or variable names.

VALUES (John, Doe, None, 5555555555, Nowhere, NY, 12345)

Should be

VALUES ('John', 'Doe', 'None', 5555555555, 'Nowhere', 'NY', 12345)

Upvotes: 3

Elon Than
Elon Than

Reputation: 9765

You have to use ' with all strings that you want to insert to database. In other case MySQL will think that you want to get value from column with given name (in this case John).

Upvotes: 0

frlan
frlan

Reputation: 7270

John is a string. You need to put in ''.

Upvotes: 0

Related Questions