Set value to NULL in MySQL

前端 未结 9 1323
逝去的感伤
逝去的感伤 2020-11-30 01:17

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

相关标签:
9条回答
  • 2020-11-30 01:51

    Use NULL (without the quotes around it).

    UPDATE users SET password = NULL where ID = 4
    
    0 讨论(0)
  • 2020-11-30 01:51

    The problem you had is most likely because mysql differentiates between null written in capital letters and null written in small case.

    So if you used an update statement with null, it would not work. If you set it to NULL, it would work fine.

    Thanks.

    0 讨论(0)
  • 2020-11-30 01:53

    Assuming the column allows a null setting,

    $mycolupdate = null; // no quotes
    

    should do the trick

    0 讨论(0)
  • 2020-11-30 01:55

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

    UPDATE table SET field = NULL WHERE something = something
    
    0 讨论(0)
  • 2020-11-30 01:58

    You should insert null, not the string of 'NULL'.

    0 讨论(0)
  • 2020-11-30 02:01
    UPDATE MyTable
    SET MyField = NULL
    WHERE MyField = ''
    
    0 讨论(0)
提交回复
热议问题