Markero M
Markero M

Reputation: 59

mysql timestamp updating error

when i'm editing information from db, there is problem with date. My date got TIMESTAMP data type. When i save(UPDATE) information, the date is 0000-00-00 00:00:00. My SQL query is -

UPDATE `news`
SET `category`='$category',
  `title`='$title',
  `img`='$file',
  `short_content`='$short_content',
  `content`='$long_content',
  `date`=$date,
  `lang`='$lang' 
WHERE `id`='$id'

$date can be something like 2013-16-06 20:35:12 but its saving as 0000-00-00 00:00:00

How to solve this problem?

Upvotes: 3

Views: 41

Answers (3)

jacek_podwysocki
jacek_podwysocki

Reputation: 807

Your date string is either empty or most likely is formatted differently that your mysql table field expects it to be. 0000-00-00 00:00:00 is mysql default value

Upvotes: 1

Fabio
Fabio

Reputation: 23480

Just surround your date with quotes

`date`='$date',

This is not an integer column, a datetime maybe, so you need to use quotes around your date

Upvotes: 0

John Conde
John Conde

Reputation: 219804

You need to put quotes around the date:

`date`='$date',

Upvotes: 1

Related Questions