I'm trying to add job info to my DB from an API.
One of my feeds supplies a date(posted) and an expiration date.
I'm trying to insert both fields (along with others).
The date gets entered fine, however the expiry date gets set to the default 0000-00-00 00:00:00
example data from api:
{
"jobId":30081256,
"expirationDate":"22/08/2016",
"date":"11/07/2016"
}
I parse the dates ready to be entered like this:
$job_date = $job->date;
$timestamp = strtotime(str_replace('/', '-', $job_date));
$date = date("Y-m-d H:i:s", $timestamp);
//expiry
$job_expiry = $job->expirationDate;
$expiry_timestamp = strtotime(str_replace('/', '-', $job_expiry));
$expiry_date = date("Y-m-d H:i:s", $expiry_timestamp);
when I echo the results of $date and $expiry_date, i get:
2016-07-11 00:00:00
and
2016-08-22 00:00:00
to me all looks good and the dates are formatted as sql would expect, but the expiry date does not get set.
I'm not sure if it has something to do with my query (shortened to show the fields in question - all other fields insert correctly):
"INSERT INTO
jobs2 (jobref, date, expiry)
VALUES ('"
.$jobref
."','"
.$date
."','"
.$expiry_date
."') ON DUPLICATE KEY UPDATE
`date` = VALUES(date),
`expiry` = VALUES(expiry)"
Maybe the ON DUPLICATE part? The job may already be in my database, but sometimes it has been refreshed/ updated and the posted date or expiry may be different so I want to keep them updated with the latest values from the API.
whats going on here?
table structure as requested:
CREATE TABLE `jobs2` (
`date` datetime NOT NULL,
`title` varchar(200) COLLATE latin1_general_ci NOT NULL,
`company` varchar(100) COLLATE latin1_general_ci NOT NULL,
`email` varchar(100) COLLATE latin1_general_ci NOT NULL,
`url` varchar(1200) COLLATE latin1_general_ci NOT NULL,
`salarymin` int(20) DEFAULT NULL,
`salarymax` int(20) DEFAULT NULL,
`benefits` varchar(100) COLLATE latin1_general_ci NOT NULL,
`salary` varchar(200) COLLATE latin1_general_ci DEFAULT NULL,
`jobtype` varchar(30) COLLATE latin1_general_ci DEFAULT NULL,
`full_part` varchar(30) COLLATE latin1_general_ci DEFAULT NULL,
`salary_per` varchar(20) COLLATE latin1_general_ci DEFAULT NULL,
`location` varchar(100) COLLATE latin1_general_ci DEFAULT NULL,
`country` varchar(30) COLLATE latin1_general_ci NOT NULL,
`description` varchar(3000) COLLATE latin1_general_ci NOT NULL,
`category` varchar(100) COLLATE latin1_general_ci DEFAULT NULL,
`image` varchar(150) COLLATE latin1_general_ci NOT NULL,
`latitude` float NOT NULL,
`longitude` float NOT NULL,
`town` varchar(50) COLLATE latin1_general_ci NOT NULL,
`county` varchar(50) COLLATE latin1_general_ci NOT NULL,
`location_id` varchar(255) COLLATE latin1_general_ci NOT NULL,
`jobref` varchar(100) COLLATE latin1_general_ci NOT NULL,
`partner` varchar(30) COLLATE latin1_general_ci DEFAULT NULL,
`company_id` int(20) DEFAULT NULL,
`featured` varchar(10) COLLATE latin1_general_ci DEFAULT NULL,
`solr_stored` int(1) DEFAULT NULL,
`expiry` datetime NOT NULL,
UNIQUE KEY `location_id` (`location_id`),
KEY `partner` (`partner`),
KEY `company` (`company`),
KEY `title` (`title`),
KEY `company` (`company`),
KEY `longitude` (`longitude`),
KEY `latitude` (`latitude`),
KEY `jobref` (`jobref`),
KEY `jobtype` (`jobtype`),
KEY `company_id` (`company_id`),
KEY `salarymin` (`salarymin`),
KEY `salarymax` (`salarymax`),
KEY `salary_per` (`salary_per`),
KEY `date` (`date`),
FULLTEXT KEY `title` (`title`),
FULLTEXT KEY `company` (`company`),
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci