Setting Field to NULL in MYSQL

Discussion in 'Programming' started by tsptom, Aug 19, 2010.

  1. #1
    I am having problems updating a specific field to NULL in MYSQL.

    $sql = "update tbluser 
             set mode ='".$mode."',
             paydate = curdate(),
             [COLOR="red"]cancel_date = '',[/COLOR]
             where username ='".$_SESSION['UserLogged']."'";
    
    mysql_query($sql) or die("Not Updated..");
    Code (markup):

    In the structure of the table, cancel_date is defined as a DATE, the NULL is set to YES, and the default is NULL.

    I have tried:
    cancel_date = NULL
    cancel_date = ' '
    and tried not updating it since it defaults to NULL.

    But for some reason when the update is executed, the field is being updated to " 1999-11-30".

    Any clues? Thanks
     
    tsptom, Aug 19, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi, try
    $sql = "update tbluser 
             set mode ='".$mode."',
             paydate = curdate(),
             cancel_date=DEFAULT(cancel_date)
             where username ='".$_SESSION['UserLogged']."'";
    
    mysql_query($sql) or die("Not Updated..");
    PHP:
    Regards :)
     
    koko5, Aug 23, 2010 IP
  3. dreteh

    dreteh Member

    Messages:
    514
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #3
    Just do
    cancel_date=NULL
     
    dreteh, Aug 23, 2010 IP
  4. tsptom

    tsptom Well-Known Member

    Messages:
    257
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    138
    #4
    Thanks! I will try that, koko5.
     
    tsptom, Aug 23, 2010 IP