My output date 1988-00-00 differs from my input date 2012-12-12 and I cannot figure out why?
I am inserting the date 2012-12-12, which sits in variable $_SESSION[CompletionDate], into a MariaDB table with the following php script:
echo"<p>CompletionDate = ".$_SESSION['CompletionDate']."</p>
mysqli_query($cxn,"INSERT INTO conservatorreport (UniqueConservatorReportRecordID,ClockID,ConservatorID,CompletionDate,ConservatorJobIdentifier,ConservatorReportFile) VALUES ('$_SESSION[UniqueConservatorReportRecordID]','$_SESSION[UniqueClockRecordID]','$_SESSION[UniqueConservatorRecordID]',STR_TO_DATE($_SESSION[CompletionDate],'%Y-%m-%d'),'$_SESSION[ConservatorJobIdentifier]','$_SESSION[ConservatorReportFile]')")
All these variables are inserted correctly into the conservatorreport table, apart from $_SESSION[CompletionDate]
which shows up in the table as 1988-00-00. The echo script sits immediately before the INSERT statement and shows:
CompletionDate = 2012-12-12
So I am convinced I am inputting 2012-12-12. I do not understand how input 2012-12-12 becomes output 1988-00-00? In the MariaDB conservatorreport table CompletionDate is defined as date.
When I leave out the STR_TO_DATE function and submit the INSERT command as follows:
mysqli_query($cxn,"INSERT INTO conservatorreport (UniqueConservatorReportRecordID,ClockID,ConservatorID,CompletionDate,ConservatorJobIdentifier,ConservatorReportFile) VALUES ('$_SESSION[UniqueConservatorReportRecordID]','$_SESSION[UniqueClockRecordID]','$_SESSION[UniqueConservatorRecordID]',$_SESSION[CompletionDate],'$_SESSION[ConservatorJobIdentifier]','$_SESSION[ConservatorReportFile]')")
I get the following error message:
Fatal error: Uncaught mysqli_sql_exception: Incorrect date value: ‘1988’ for column
conservatorreport
.CompletionDate
I spent several days trying to find the bug and begin to believe it is something in the MariaDB which causes this, but I do not know where to look.
My database server details are:
Server: Localhost via UNIX socket
Server type: MariaDB
Server connection: SSL is not being used Documentation
Server version: 10.4.28-MariaDB – Source distribution
Protocol version: 10
User: root@localhost
Server charset: UTF-8 Unicode (utf8mb4)
My web server details are:
Apache/2.4.56 (Unix) OpenSSL/1.1.1t PHP/8.2.4 mod_perl/2.0.12 Perl/v5.34.1
Database client version: libmysql – mysqlnd 8.2.4
PHP extension: mysqli Documentation curl Documentation mbstring Documentation
PHP version: 8.2.4## Heading ##