This is driving me crazy. It WORKS for one field, but not the other:
[php] $spouseb = trim($_POST[‘spouse_birthday’]);
if($spouseb != ‘’) {
$sbirth = “’”.date(“Y-m-d”,strtotime(str_replace(’-’,’/’,$spouseb)))."’"; }
else { $sbirth = “NULL”; }
$memb = trim($_POST['birthday']);
if($memb != '') {
$mbirth = "'".date("Y-m-d",strtotime(str_replace('-','/',$memb)))."'"; }
else { $mbirth = "NULL"; } [/php]
Then, my update query is simply:
spouse_birthday = $sbirth,
birthday = $mbirth,
So, the $sbirth block works. If no date is entered into the form, the query inserts a NULL value.
$mbirth block? I get: 12/31/1969 and not NULL
If I enter actual dates and not leave the fields blank, the dates are formatted and inserted correctly.
In the database, both spouse_birthday and birthday are date fields, with no default value set. Nulls are allowed.
As a test, I can delete all the form vars and date formatting and just set the two variables to NULL
[php]
$sbirth = “NULL”;
$mbirth = “NULL”;[/php]
Now, I KNOW my values are null. The update STILL inserts 12/31/1969 for $mbirth, and NULL for $sbirth.
Ideas? Before I pull ALL my hair out? Why will it insert NULL for one, but not the other?