I'm trying to insert dates into a mysql database using PHP. However, the insert query brings up this error when I press submit on the form.
PHP Fatal error: Call to a member function format() on boolean
$show_date1 = DateTime::createFromFormat('d/m/Y', $publicexpiry)->format('Y-m-d');
$sql = "INSERT INTO " . $config_tbl_prefix . " subcontractor_qs (nameofcompany, mainaddress, natureofbiz, telnum, publicexpiry)
VALUES
('" . mysql_real_escape_string($nameofcompany) . "', " . mysql_real_escape_string($mainaddress) . ", '" . mysql_real_escape_string($natureofbiz) . ", '" . mysql_real_escape_string($telnum) . ", '" . mysql_real_escape_string($show_date1) . "')";
Any help would be greatly appreciated. I am using this code on another page with an update query and this works as it should. So I can't understand what's going wrong. I have tried other answers to similar questions but they don't work for me.