FIND THE ANSWERS

How do I get php to insert a blank into MySQL where it is set to be an integer?

Answer this question

  • How do I get php to insert a blank into MySQL where it is set to be an integer?


Answers

Answer #1 | 28/12 2013 22:13
if($year == "") { mysql_query("UPDATE mytable SET year = NULL WHERE id = '$id'"); }
Answer #2 | 28/12 2013 22:19
Untested, but I would expect this to work: "UPDATE mytable SET year = $year ? '$year' : NULL WHERE id = '$id'" I think for an int field, a value of '' in mysql translates to a 0. If you want NULL instead of 0, you need to state NULL explicitly. Of course, it will only work if the year field is NULLable to begin with.

Possible answer

Anonymous643669
Login to your account
Create new account