Update query unable to set an integer as NULL !

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aditi_19
Forum Newbie
Posts: 23
Joined: Sun Jun 21, 2009 3:09 pm

Update query unable to set an integer as NULL !

Post 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?
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

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

Post 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
aditi_19
Forum Newbie
Posts: 23
Joined: Sun Jun 21, 2009 3:09 pm

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

Post by aditi_19 »

So what should be done?
Post Reply