Hi hope someone can help me
How can i update a date field to NULL so that i have 0000-00-00 in the date field

i have the following code but it's not working i tried a lot of things but nothing wil work

if($_POST['geboortedatum'] == "")
        {
        $date = NULL;
        $updatequeryz = "UPDATE stamboom_dohmen SET geboortedatum='$date' WHERE id='$idpersoon'";   
        mysql_query($updatequeryz) or die (mysql_error()); 


        }

Thanks in advice John

Member Avatar for diafol

I think the datefield by default stores NULL. If you want this then

$updatequeryz = "UPDATE stamboom_dohmen SET geboortedatum=NULL WHERE id=$idpersoon";

Without the single quotes

You can alter the field to accept a default of 0000-00-00 if you want. Then ionstead of supplying NULL you supply '0000-00-00'. Supplying NULL in the query will set the value to NULL not 0000-00-00.

sorry but that dosn't work it give me always the date of today
I have to tell the mysql field id set to DATE

even i tried
$updatequeryz = "UPDATE stamboom_dohmen SET geboortedatum='' WHERE id=$idpersoon";

Sorry i have found it i had a misstype in a pease of javascript
and that was
onclick="document.getElementById('demo1').value=' ' "
i change it in
onclick="document.getElementById('demo1').value='' "

whan i use

$updatequeryz = "UPDATE stamboom_dohmen SET geboortedatum=NULL WHERE id=$idpersoon";

it give the date 1970-01-01

and

$updatequeryz = "UPDATE stamboom_dohmen SET geboortedatum='' WHERE id=$idpersoon";

wil give 0000-00-00

thanks for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.