在 MySQL 中将值设置为 NULL

2021-11-20 00:00:00 sql mysql

如果我提交的表单的文本框中没有放入任何内容,我希望将一个值设置为 NULL.我怎样才能做到这一点?我试过插入 'NULL' 但这只是将 NULL 这个词添加到字段中.

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.

我不确定我应该为此提供什么代码,我只是在写一个 UPDATE 查询.

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

推荐答案

不要将 NULL 放在更新语句中的引号内.这应该有效:

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

UPDATE table SET field = NULL WHERE something = something

相关文章