Page 1 of 1

Update query unable to set an integer as NULL !

Posted: Wed Jul 08, 2009 8:23 pm
by aditi_19
Hello,

I have created a php page to update some data. While changing an integer or Date field value to NULL, the update query does not run fine. It still displays the old value instead of setting it to NULL. It doesn't work well with drop down lists also !

Code: Select all

$query = "UPDATE tbluserlist SET UserID = '$userid',
                  FirstName = '$fn',
                  LastName ='$ln' ,
                  Initials ='$initials',
                  BirthDate = '$birthdate',
                  WorkPhone = '$workphone',
                  DateOfHire = '$datehire',     //date
                  Status='$status',                // a drop down list
                  Extension='$extension',
                  AccruedSickTime = $accruedsicktime    //integer
                 WHERE UserID ='$userid';";
What should be done to make it run well for all these 3 cases?

Re: Update query unable to set an integer as NULL !

Posted: Wed Jul 08, 2009 9:05 pm
by Eric!
Nulls are different from empty strings and mysql handles nulls for different data types differently. For example inserting a null into a timestamp field will produce the current date/time....

http://dev.mysql.com/doc/refman/5.0/en/ ... -null.html

Re: Update query unable to set an integer as NULL !

Posted: Wed Jul 08, 2009 9:48 pm
by aditi_19
So what should be done?