Set value to NULL in MySQL

muttley91 picture muttley91 · Feb 16, 2012 · Viewed 359.1k times · Source

I want a value to be set to NULL if nothing is put into the text box in the form I'm submitting. How can I make this happen? I've tried inserting 'NULL' but this just adds the word NULL into the field.

I'm not sure what code I should provide for this, I'm just writing an UPDATE query.

Answer

Fosco picture Fosco · Feb 16, 2012

Don't put NULL inside quotes in your update statement. This should work:

UPDATE table SET field = NULL WHERE something = something