I am trying to handle if either NULL or a datetime object is passed to my handler while still writing NULL to the database and not just 00000000
I can get it to work if I parse the stop_date first and then depending on what it is, send it through 2 entirely different queries, but I want to be able to do it in one query either way
if(strtolower($stop_date) != 'null'){
$stop = date("Y-m-d H:i:s", strtotime($stop_date));
if($stop <= date('Y-m-d H:i:s')){
die('No stop date was entered for this appointment. Recurring appointments must have a stop date or marked "NULL" if they do not have a stop date');
}
}
else{
$stop = NULL;
}
$db->query("
UPDATE appt_recurring
SET hc_id = :hc_id, note = :note, appt_type_id = :appt_type_id, start_date = :start_date, end_date = :end_date,
stop_date = (
CASE
WHEN
".$stop." != NULL
THEN
:stop_date
ELSE
$stop
END
),
frequency = :frequency, frequency_type = :frequency_type, frequency_data = :frequency_data
WHERE id = :id
");
$db->bind(':id', $id );
$db->bind(':hc_id', $hc_id );
$db->bind(':note', $note );
$db->bind(':appt_type_id', $appt_type_id );
$db->bind(':start_date', $start_date->format('Y-m-d H:i:s'));
$db->bind(':end_date', $end_date->format('Y-m-d H:i:s'));
if(strtolower($stop_date) != 'null'){
$db->bind(':stop_date', $stop);
}
$db->bind(':frequency', $frequency );
$db->bind(':frequency_type', $frequency_type );
$db->bind(':frequency_data', $frequency_data );
This provides nothing but syntax errors and in some cases with some tweaking a parameter error. Please help!