MySQL v5.6.20; Table in question:
CREATE TABLE `invoices` (
`INVOICE_NUMBER` smallint(4) unsigned NOT NULL AUTO_INCREMENT,
`INVOICE_DATE` date DEFAULT NULL,
`PROJECT_NUMBER` smallint(4) unsigned DEFAULT NULL,
`CLIENT` tinytext COLLATE utf8_unicode_ci,
`PROJECT_DESCRIPTION` tinytext COLLATE utf8_unicode_ci,
`TOTAL_HOURS` text COLLATE utf8_unicode_ci,
`SUBTOTAL` decimal(10,2) unsigned DEFAULT NULL,
`TAX` decimal(10,2) unsigned DEFAULT NULL,
`INVOICE_TOTAL` decimal(10,2) unsigned DEFAULT NULL,
`DATE_SENT` date DEFAULT NULL,
`DATE_RECEIVED` date DEFAULT NULL,
`NOTES` text COLLATE utf8_unicode_ci,
PRIMARY KEY (`INVOICE_NUMBER`)
) ENGINE=InnoDB AUTO_INCREMENT=1005 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
And the pertinent bits of my process.php are:
if (isset($_POST['submit'])) {
$invNum = $_POST['invNum'];
$invDate = $_POST['invDate'];
$projNum = $_POST['projNum'];
$client = $_POST['client'];
$projDesc = $_POST['projDesc'];
$totalHours = $_POST['totalHours'];
$subTotal = $_POST['subTotal'];
$tax = $_POST['tax'];
$invTotal = $_POST['invTotal'];
$dateSent = $_POST['dateSent'];
$dateReceived = $_POST['dateReceived'];
$notes = $_POST['notes'];
$notes = mysqli_real_escape_string($mysqli, $notes);
echo "<div class=\"debug\">
<table>
<snip>( SUCCESSFULLY ECHOING ALL VARIABLES/VALUES )</snip>
</table>
</div>";
$query = "INSERT INTO Invoices SET
INVOICE_NUMBER = '$invNum',
INVOICE_DATE = '$invDate',
PROJECT_NUMBER = '$projNum',
CLIENT = '$client',
PROJECT_DESCRIPTION = '$projDesc',
TOTAL_HOURS = '$totalHours',
SUBTOTAL = '$subTotal',
TAX = '$tax',
INVOICE_TOTAL = '$invTotal',
DATE_SENT = '$dateSent',
DATE_RECEIVED = '$dateReceived',
NOTES = '$notes'
ON DUPLICATE KEY UPDATE
INVOICE_NUMBER = VALUES(INVOICE_NUMBER),
INVOICE_DATE = VALUES(INVOICE_DATE),
PROJECT_NUMBER = VALUES(PROJECT_NUMBER),
CLIENT = VALUES(CLIENT),
PROJECT_DESCRIPTION = VALUES(PROJECT_DESCRIPTION),
TOTAL_HOURS = VALUES(TOTAL_HOURS),
SUBTOTAL = VALUES(SUBTOTAL),
TAX = VALUES(TAX),
INVOICE_TOTAL = VALUES(INVOICE_TOTAL),
DATE_SENT = VALUES(DATE_SENT),
DATE_RECEIVED = VALUES(DATE_RECEIVED),
NOTES = VALUES(NOTES)
";
Why am I getting errors when submitting my form with various fields empty, e.g.:
"INSERT failed: (1366) Incorrect decimal value: '' for column 'TAX' at row 1", or "INSERT failed: (1292) Incorrect date value: '' for column 'DATE_SENT' at row 1"
... despite the fact that - at least according to my newbie understanding, the definition of these fields should allow null (= empty?) values? Not surprisingly, the error will occur only on the first empty field, regardless of how many fields are empty. My understanding is that I should be able to execute an insert query with some empty fields; at some point in the recent past, I was able to do so, though I have recreated this table in the wake of other issues (and suspected corruption), but it seems that something in how I created or tweaked this table is the cause of this soul-crushing disappointment.
Also adding to my confusion is the fact that there is a second INSERT query running on the same page (process.php), following the one described above, which successfully inserts data into the Invoice_Line_Items table despite empty 'HOURS' field, which is defined thusly: (decimal(10,2) unsigned DEFAULT NULL); as far as I can tell, the problematic fields in the Invoices table are similarly defined.
Many thanks in advance,
svs