I spend too many hours trying to pass null value to null coloumn in database and all the solution that I google it didn't work for my code it give me this error :
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: '' for column 'DateOfImplementation' at row 2
here is the query that update the table :
<?php
function updateDates($ApplicationID , $DateOfImplementation , $DueDate ,$FinanceDeliveryDate ,$FinanceReceiptDate){
try {
$dbc = new db();
$dbhc = $dbc->connect();
$sql = "UPDATE `applicationstudy` SET
`DateOfImplementation` = '$DateOfImplementation',
`DueDate` = '$DueDate',
`FinanceDeliveryDate` = '$FinanceDeliveryDate',
`FinanceReceiptDate` = '$FinanceReceiptDate'
WHERE `ApplicationID` = '$ApplicationID' ;";
if( $dbhc->exec( $sql ) ) {
return true;
}
else {
return false;
}
$dbhc = null;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
?>
here is the post for insert the dates :
<?php
if ( isset( $_POST["applicationid"] ) ) {
$applicationid = $helperObj->prepar_data( $_POST["applicationid"] );
}
if( ! is_null( $_POST["FinanceDeliveryDate"] ) ) {
$FinanceDeliveryDate = $helperObj->prepar_data( $_POST["FinanceDeliveryDate"] );
} else {
$FinanceDeliveryDate = 'NULL';
}
if( ! is_null( $_POST["FinanceReceiptDate"] ) ) {
$FinanceReceiptDate = $helperObj->prepar_data( $_POST["FinanceReceiptDate"] );
} else {
$FinanceReceiptDateFil= 'NULL';
}
if( ! is_null( $_POST["DueDate"] ) ) {
$DateOfFirstInstallment = $helperObj->prepar_data( $_POST["DueDate"] );
} else {
$DateOfFirstInstallment ='NULL';
}
if( ! is_null( $_POST["DateOfImplementation"] ) ) {
$DateOfImplementation = $helperObj->prepar_data( $_POST["DateOfImplementation"] );
} else {
$DateOfImplementation = 'NULL';
}
$status = $appstudyobj->updateDates( $applicationid , $DateOfImplementation , $DateOfFirstInstallment ,$FinanceDeliveryDate ,$FinanceReceiptDate );
?>
How can I insert null value it work if there is no single quotation in the function but doesn't take the value correct if there is a date