I'm trying to update date field in my db. Query like this:
$q = "update news set data = STR_TO_DATE('2011-03-05','%Y-%m-%d'), title = '".$title."', content='".$content."',....";
works great, but:
$q = "update news set data = STR_TO_DATE('".$data."','%Y-%m-%d'), title = '".$title."', content='"...";
it is not working :(
I got date:
$data = $_POST["data"];
and it has a value "2013-04-13". I trimmed date and show in popup window and value is correct; Plz help :)
UPDATE It is strange to me, but if i'm using:
$q = "insert into news set data = CAST('".$data."' AS DATE), title = '".$title."', content='".$content."'...";
it works perfectly fine. Only in insert not in update
Script for table:
CREATE TABLE IF NOT EXISTS `news` (`id` int(11) NOT NULL AUTO_INCREMENT, `data` date NOT NULL, `title` text NOT NULL, `content` text NOT NULL, `img` text NOT NULL, `n_img` text NOT NULL, PRIMARY KEY (`id`), KEY `id` (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=36 ;