MySQL trouble fix: unknown column in ‘field list’

Just a note that when you’re trying to insert data into a table and you get the error

Unknown column ‘the first bit of data what you want to put into the table‘ in ‘field list’

using something like

INSERT INTO table (this, that) VALUES ($this, $that)

it’s because you’ve not got any apostrophes around the values you’re trying to stick into the table. So you should change your code to:

INSERT INTO table (this, that) VALUES (’$this’, ‘$that’)

Nearly drove me mad, that one.

Ian 2nd March 2006

You won’t believe how mad that was driving me! Thanks!

Howard 8th March 2006

Me too, many thanks

Jared 16th March 2006

Thanks for the help!

JimmyC 27th March 2006

Thank you very much for this piece of information…

Fintan 30th March 2006

You’re welcome, everyone - it’s silly there’s no good documentation for this problem on the interweb!

flip 2nd April 2006

THANKS A LOT!!! sorry I shout, but it helped me very much!
thank you again!

Fintan 2nd April 2006

lol

PC Troll 26th April 2006

Thank you so much. I was really frustrated. Thank God there’s people like you who share the knowledge. See ya later and keep being successful and nice.

Samuel 7th May 2006

I’ve found that adding ticks to both the column fields and the values will cause the same error. For example:

INSERT INTO table (`this`, `that`) VALUES (`$this`, `$that`)

will cause the same error as

INSERT INTO table (this, that) VALUES ($this, $that)

chris 6th July 2006

THAAAAAAAAAAAAAANK YOOOOOOOOOOOOOOu

Dewert 9th July 2006

Hehe there’s a guy who posted a bug report about this on the mySQL site. Poor fellow, eh? Anyway, thanks for this concise reminder, which saved me loads of googling, and got me straight to the self-kicking.

Tom 24th July 2006

I love you, will you have my babies? May I have your babies? Thank you for taking this offer into consideration.

Max 26th July 2006

That error can happen other times to, even when you have the quotes and such. I get it once and a while and my friend keeps getting it, just switch the field names around in the table and it usually works. Not sure why…

Mank 3rd September 2006

Just a note, make sure to use a normal apostrophe (single quote: ‘) instead of the “grave accent” (or whatever: `) if you’re still having problems.

Paul Mellon 18th September 2006

cheers dude, been trying to work it out for days!

alala 22nd September 2006

Oh man, that is so helpful, thank you! You are my current hero.

Aaron 4th October 2006

Thank you so much!!!

Moises Rosales 13th October 2006

i had this error and was insaneee. tried a lot of procedures and incredibly this was my solution:

$add_all = ‘INSERT INTO ‘.$table.’ (IDTRANSACC, FECHATRANS, NOMPROD, IDPED, RECIB, SALIDA) VALUES (NULL, ‘.$fecha.’, “‘.$nomprod.’”, NULL, ‘.$recib.’, NULL)’;
mysql_query($add_all) or die(mysql_error());

REALLY CRAZY ISNT IT?

can someone explainme why i cant do like this:
$add_all = ‘INSERT INTO ‘.$table.’ (IDTRANSACC, FECHATRANS, NOMPROD, IDPED, RECIB, SALIDA) VALUES (NULL, ‘.$fecha.’, ‘.$nomprod.’, NULL, ‘.$recib.’, NULL)’;
mysql_query($add_all) or die(mysql_error());

Dan 26th October 2006

Gracias amigo!

Oscar 10th November 2006

Really thanks dude!

Muchas Gracias.

mc2 10th January 2007

Thanks,

It help me a lot ! !

Elliott 11th January 2007

In the immortal words of Charlton Heston, “A mad house!”

Many thanks!

Sean Delaney 15th February 2007

Thank you - This helps me a lot!!

daph 18th March 2007

Thank you very VERY much for the information !! Saved me a lot of time :-)

Menta 12th April 2007

Woow, is there an explanation for this ? I was doing a select query and he did’nt find a numeric column untill I added the ticks.

Karen 25th April 2007

Thank you!

oldfriend 4th May 2007

Thank’s God you wasn’t born in the 18 century!

Cami 7th May 2007

This helps me a lot !
Thank you

chris 9th May 2007

Thanks for this

I realise I am saying no more than the rest of the people above - but in all seriousness this was driving me nuts - variables shouldnt need ‘

Cheers

Chris

JustMadMike 30th June 2007

Thankyou VERY much!

Illidan 30th June 2007

You’re my hero.

wellwisher 8th July 2007

Thanks a lot!

Isaac 19th August 2007

thanks a lot man!!! you saved one brain from a bullet!! go cowboys!!

James 28th August 2007

Thanks, helped me today….wasted about 20 minutes before realizing someone else could have done the samething. =X

Frizzy 28th August 2007

Thank you :D:D:D

Kien 2nd September 2007

I am teaching myself PHP/mySQL and wasted more than 48 hours trying to insert the values without success - until I got to your page. Thank you!

Abhishek 4th September 2007

Thank you. Thank you. Thank you!! This small post was a Great help.

tim 5th September 2007

Thanks a lot … This helped. BTW if tom is not having your babies, Can he have mine instead ?

George 15th September 2007

Not only was your post right to the point and incredibly helpful but you were also the first google hit, sometimes life is simple. Thanks

Karnith 24th September 2007

It also helps if you recheck the db and insure if the field you want to be filled is there.

erwin 25th September 2007

thank’s ……1000x :)

william 25th September 2007

yeh mate, good one my friend, iw as stuck and thought IT IS IMPOSSIBLE

but it was very possible

and now plausible

dot 5th October 2007

fucken ell thanx!

chris 14th October 2007

you have NO IDEA how many hours I’ve been trying to fix that one. Thanks!

:)

drivethru 19th October 2007

thanks! how frustrating was that… can’t use quotes, has to be single quote. and just another note, if you are using MS word they’re single quotes don’t work either, use notepad.

Alex 23rd October 2007

Thank you so much. This was so obscure and irritating

KRiSTEN 25th October 2007

THANK YOU! You wouldn’t believe how difficult it was to find a solution to this simple problem!

Cami 3rd November 2007

test

ZC 9th December 2007

10x a lot man!

Dave 10th December 2007

Found this through google - it’s saved me afters hours of frustration!

Matthew Vines 14th December 2007

I’ve also run into this problem at the end of long Data Layer days. Where I mis-spell the table name in my stored procedure or query. The wording of the error tends to make you focus on the column in question, but it can be caused by quite a lot of things. Also, for those that have noticed that changing the order of the columns seems to work. I wouldn’t be surprised if after you change the order and run a successful test, you can change the order back, and it will still work. Most likely, when you move the text you are removing the offending whitespace character that is causing the Information Schema query to protest. Thanks for taking the time to post on this.

Matt

pm 17th December 2007

Again, Thanks so much……

Robert 21st December 2007

Hey I have run into this problem also and I have actually written it the way your doing my customers website is a ASP application with MySQL 5.0.22 as DB

My actual code look like this:

Conn.execute(”INSERT INTO myTable (this,that,other) VALUES (’”& strThis &”‘,’”& strThat &”‘,’”& strOther &”‘)”)

Does anyone have any suggestions on how to fix this? considering the syntax seems to be correct according to this article.

Thanks,

strongyin 22nd December 2007

Thank you ,I have solved this problem!

Inno 24th December 2007

Hey guys,

I realize you all seem happy, but when I tried to do an update on a table, I get the same error, even though the field exists, and is printed in the Metadata that I got from the Resultset. unfortunately, I cannot swap my column positions….

H.Luup 29th December 2007

Thank you very much.

Lars Frederiksen 2nd January 2008

Thanks a lot!
I had the same problem with UPDATE.

$query = “UPDATE dagplan SET f1 = $ny WHERE dagplan_id = $row[dagplan_id]“;

changing it (thanks to your advice!) to…

$query = “UPDATE dagplan SET f1 = ‘$ny’ WHERE dagplan_id = $row[dagplan_id]“;

Made it run without problem.

Jyaif 3rd January 2008

my savior

Borodon 8th January 2008

Thanx indeed

bicho 11th January 2008

=), obrigado!!, legal

Marty 16th January 2008

Thanks!

I’ve had problems with the keeping the ‘ around the variable when it comes to adding a NULL value to a table using amfphp.

Be nice not to have to try finding work arounds when the issue pops up.

Cheers,

Marty

Suryanshu Urmaliya 17th January 2008

this is awesome job bro………Had glitches while installing a site to clients server and I thought that it was server issue…..Thanks to Google and thanks to you……………

David 25th January 2008

You are my hero!
Thanks!

Nando 27th January 2008

Hello people, i have a big trouble, thats my code:

5- $sql->query(”INSERT INTO accounts (login, password, lastactive, access_level, lastIP, email)
6- VALUES(’$login’, ‘$pass’, ‘$lastactive’, ‘0′, ‘$last_ip’, ‘$email’)
7- “,”LS”);

thats the errorrrrrrrrrr.

MySQL ERROR: Unknown column ‘e_mail’ in ‘field list’

its drive me crazy, please, if you need the full code, told me.

sorry for my english, hasta pronto!

Graham 1st February 2008

You are a ledgend!

YURBAN 22nd February 2008

GREAT THX MAN!!!

Toasted 26th February 2008

Yay, woot! It works, you are a genius. Was driving mad. Spent the last hour and half trying to find the error….cheers

fatima 4th March 2008

thank you sooooooooooooooooooo much!!!!!luckly i found this site. or else, i’ll get crazy just like you guyyyyyyssssssssss!!!!!!!!!!

ruben 4th March 2008

thankyou guy so much, now i can go to sleep , hope not dreaming with Unknown column ‘pepe’ in ‘field list’

James 10th March 2008

Adding my name to the roll-call of thanks!

Little, helpful and googlable tidbits like this make the web.

Anthony 11th March 2008

Ok. I’ve been trying to get this to work for hours and so many of the websites on top of this one remark “Hey idiot you have a column listed that doesn’t exist” and I knew that that wasn’t the problem. Thank you SOOOO much.

gina 26th March 2008

thank you so much for this insight! *such* a weight off my shoulders.

amehna 7th April 2008

You guys are the best. I have trying to do this for days but couldn’t figure it out. And now it worked like a charm.

Thanks

rixmbx 10th April 2008

The thanks keep rolling in!
Thanks for the post!
You have helped me maintain the little sanity I have left!

Caio Iglesias 18th April 2008

…and another soul was helped. thanks!

DC 19th April 2008

ok, this is still not working for me….here is my error…

————————————————–
A Mysql error has occurred while running the script:

The query you are trying to run is invalid.
Mysql Error Output: Unknown column ‘activation_key’ in ‘field list’
SQL Query: UPDATE probid_gen_setts SET activation_key=’[--activation key--]‘
————————————————–

Arnie Abrahamson 22nd April 2008

Yet another thank you!

Shouldn’t this point be better documented in the literature / tutorials out there? Spread the word, everyone!

pope t 23rd April 2008

Saved my reamining hair from being pullled from my head through sheer frustration - you are a saint sir

God bless you

Priya 30th April 2008

That was of great help! Thanks much!!!

javier 30th April 2008

this help me a lot , thanks

uinoz 1st May 2008

Thanks a lot for this tip, you saved me a lot of time :)

growch 5th May 2008

Bless you kind sir. And bless google for pointing me to this.

nguoi_ban_xu 12th May 2008

INSERT INTO `FeedBack` (den_tu,tieu_de,noi_dung,trang_thai) VALUES (`Aptech`, `Feedback sach` , `Ko hay lam`, 1)
–> #1054 - Unknown column ‘Aptech’ in ‘field list’ ???

emar2 14th May 2008

thanks heaps!

Yaaay! 16th May 2008

Thank you very much!!!

Alan 25th May 2008

Thanks a lot!!

Naresh 27th May 2008

Now i have tried everything u said in the quotes and not in the quotes and all that but it was leaving me an error on line 1.

Here is what i did, there was an email field for which i changed the type from varchar(20) to varchar(25).

The error was the same but in line 1.

I simply restarted the MySQL server and it was all good and fine working..
Just thought i wud share for further references.

John 28th May 2008

thanks! I was pulling hair on this one!

Frank 19th June 2008

Thanks, was having this problem too, just tried it again and it worked like a charm.

Raphaei 23rd June 2008

Thank you =)

clems 27th June 2008

Thank you :)

Rhu 28th June 2008

Life savour!

pavan 2nd July 2008

thanks a lot

Charles 2nd July 2008

Thank you, thank you, thank you…was about to go bald…

Luis 5th July 2008

I need help. Consider the database:
char | num
a | 1
b | 3
a | 4
b | 2
b | 4
d | 2
d | 1
c | 1
a | 2

I want to get a limited list for 2 ordered charaters:
a | 1
a | 4
a | 2
b | 3
b | 2
b | 4

I need to limit the counter characters, for example:
LIMIT 1, 3 may be result:

b | 3
b | 2
b | 4
c | 1
d | 2
d | 1

Who is the mysql command to do this?
Any help?

Tony 11th July 2008

Thank you so much…I hate how anal mysql is about syntax

Mihir 13th July 2008

Thanks!!

sam 15th July 2008

Error: Unknown column ‘name’ in ‘field list’

come up with error i have done this and wot the other guy sugessted wth is up

chonz0 21st July 2008

Wow, two years and still helping people, people like me =P
THANKS MAN! It was driving me crazy!!!
({)

rufik 21st July 2008

But what’s up with the same error while using prepared statements in java??

Chriushikas 31st July 2008

Hello people,
for example your making query that you want to insert it to database but also your want to make an archive of the query command to the other database…

so in first query use:
$query = “…VALUES (”\”.$sentance.”\”, “\”.$who.”\”, …)”;

this will solve your problems ;)

Juln 31st July 2008

I ran into this issue using prepared statements with PDO…

I thought I remembere3d what I was doing, I did this:

$sql=”insert into my_table values (’0′,$squid,$pickle,$duckling_id)’;

$statement=$pdo_db->prepare($sql);
$is_success=$pdo_db->execute();

this will give the same error, because I am not using prepared statements right.

the right way is of course:

$sql=”insert into my_table values (’0′,?,?,?)’;
$data=array($squid,$pickle,$duckling_id);

$statement=$pdo_db->prepare($sql);
$is_success=$pdo_db->execute($data);

Silly me.

lanrod 2nd August 2008

thanks much!

Dazed&Confused 2nd August 2008

Hi - thanks for the tip! I have a line of code that goes like this:
“UPDATE tablename SET myvar= ‘ ” . $myvar . ” ‘ WHERE Name = ‘ ” . $name . ” ‘ “;

I keep getting the same message that you had:

Unknown column ‘myvar’ in ‘field list’

any ideas?

KenzoIX 4th August 2008

Thanks you man, that helps me a lot :D

Al Toman 5th August 2008

Fintan,

I’ve gone mad~! Decided to google “mysql Unkown column” and voila~!

Now, back to sanity.

… until the next event.

thanks~!

lenz 8th August 2008

thanks for the tip. you saved me many hours of googling.

Paul 12th August 2008

Thanks a lot. Its been driving me mad too

Rich 12th August 2008

Awesome!!!!

O’ve been pullin me hair owt over that one for days!!!!

Ionutz 13th August 2008

you saved me from hours of searching. very very good post

Esa 13th August 2008

Thanks a bunch, another soul helped.

Nice blog by the way, an excellent layout, clear and beautiful.

aledujke 4th September 2008

How did I missed that!?

jacko 10th September 2008

THANK YOU THABK YOU TRHANK YOU THANK YOU THANK YOU

mos 21st September 2008

Thank you!

regin 23rd September 2008

I tried it in my script and it didnt work UNTIL I switch places of my column names…I dont know this happens…my nose nose is bleeding now got to go to hospital fast….

syncho 24th September 2008

yay! thanx :D

bano 24th September 2008

thank you very much!!

You were the first one at Google and the solution for my problem.

Terrell 6th October 2008

Thank you alot!

Dart 10th October 2008

Whooot, thank you so much. You saved my day , this thing have been driving me crazy :) God bless you

But ofcourse 28th October 2008

You were my google solution. Thanks :D

AHA 7th November 2008

Man, THANX

Marvin Ochieng 11th November 2008

Hi, i have this query,

SELECT modx_site_content.id, modx_site_content.pagetitle, modx_site_content.content, modx_site_tmplvar_contentvalues.value FROM modx_site_content WHERE modx_site_content.parent = 16 OR modx_site_content.parent = 22 AND modx_site_tmplvar_contentvalues.contentid = modx_site_content.id ORDER BY RAND() LIMIT 1

which tells me unknown table ‘modx_site_tmplvar_contentvalues’ in field list but i’ve confirmed its there. what could be the problem?

Marvin Ochieng 11th November 2008

seen the error, sorry

duddeel 14th November 2008

THANK U !!!!

arc 19th November 2008

1054 - Unknown column ‘clickandbuy_TransactionID’ in ‘field list’

update customers_basket set final_price=’0′, clickandbuy_TransactionID=’8ea284a’, clickandbuy_externalBDRID=’8e22a20a72′ where customers_id=”

veena 19th November 2008

Exception :Data truncation: Out of range value adjusted for column ’salary’ at row1

if u can solve it please reply me

bliz 28th November 2008

i had a brain fart and totally forgot about it…thanks!!!

yuliang 1st December 2008

Thank you very much!

Mike B 3rd December 2008

THANK YOU !!!!!!

Abu Yahya 7th December 2008

Ooooooh! Thank you sooo much!

I became half mad because of this until I Googled and found this result. And this wasn’t even the first time….

Anonymous 7th December 2008

Tupo

thanasisdev 8th December 2008

hi there,

i had the exact same problem. All good with the apostrophes but the problem kept coming up.

The explanation to my problem was that when i switch to see my database in PHPMyadmin, i found out that the offending columns had SPACES before them- YES WHITESPACES that do not show while you view your columns in the phpmyadmin.
You have to actually EDIT the column names in order to see the real value with the spaces.

So i guess this is probably because of Copy-Pasting the column-names…So from now on, ensure that you have manually constructed your database with your own hands, not just with copy-pasting

Thanks again - I hope that this will solve a lot more ppl from the same problem.

Be4orez 16th December 2008

Wow, thank you very much.
Also, your SEO is good.

I entered this in the adressbar:
Unknown column ‘public’ in ‘field list’
and google/firefox redirected me instantly to this simple but very helpfull solution.
Thanks ;)

Gregg 22nd December 2008

Thank you for posting your frustrations - I was so close and this fixed it - thanks!!

Richard 23rd December 2008

Thanks! That did the trick :-)

Varun 23rd December 2008

Dude, you are a life saver! I tried every possible permutation and combination before I got this tip from you!

Pato 1st January 2009

Hi guys, happy new year!

I have the same problem but I can’t fix it!! I checked the ‘ and they are fine, I checked the db table in phpmyadmin and its fine, this is really driving me nuts, I haven’t slept in 2 days now!!

Here is the link for the page giving me trouble: http://www.pgiovannini.com/diagnostico/agregarUsuario.php

The error I get is this one: Unknown column ‘text’ in ‘field list’

I hope you guys can help me out! Thanks!

Pato 1st January 2009

OK never mind, I got that one fixed…. But now is giving me another error:

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 ‘±a, NombreUsuario, ApellidoUsuario, EmailUsuario, TipoUsuario FROM usuarios ORDE’ at line 1

Any ideas?

Pato 1st January 2009

Never mind, bot both working, thanks!

Leave a Reply