null date field

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
nikko50
Forum Commoner
Posts: 43
Joined: Thu Apr 08, 2004 6:28 am

null date field

Post by nikko50 »

Hello,
I have a date field with a default of NULL. If a user enters a date and then decides to update that date field, how can I set it back to NULL?? I tried
$charged = 'NULL';

$query= "UPDATE customers SET charged= '$charged'
WHERE orderid='$orderid'";

But that just sets the field to 0000-00-00. Why is it doing that when the default is set to NULL.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

that is because 'NULL' is not the same as NULL

Code: Select all

if ($charged == 'NULL')
{
    $query = "UPDATE customers SET charged = NULL";
}
else
{
    $query = "UPDATE customers SET charged = '$charged'";
}
Post Reply