So.. I dont know why i cant find a specific tutorial / tip on this, so i'll ask you guys.

I'm trying to get $date to get the current date and insert it as the query executes.

$result=mysql_query("INSERT INTO articles (`loginid`,`title`,`author`,`body`,`date`,`category`) VALUES ('$loginid','$title','$author','$body','$date','$category')")

this is my Database.

CREATE TABLE `articles` (
  `id` int(20) NOT NULL auto_increment,
  `loginid` varchar(19) NOT NULL,
  `title` varchar(25) NOT NULL,
  `author` varchar(30) NOT NULL,
  `body` text NOT NULL,
  `date` date NOT NULL default '0000-00-00',
  `category` varchar(100) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=39 DEFAULT CHARSET=latin1 AUTO_INCREMENT=39 ;

i have tried different date formats like getdate, strftime(, strtotime etc.
But i get this error when i try execute the post script.

Insert Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<<<$body text was here i just changed it to this>>>>

Have you tried date function? Some information on the functions you've tried with: getdate function returns an array and I do not think sql's date format would accept it. strftime function, to my knowledge, has compatibility issues and it requires you to set the locales. strtotime gives you a timestamp.

Member Avatar for diafol

Which format is being sent by the form? 'Y-m-d'?

I'd suggest storing dates in unix timestamp format (integer). I might be laughed at for that, but arithmetic-based calculations tend to be easier.

Which format is being sent by the form? 'Y-m-d'?

I'd suggest storing dates in unix timestamp format (integer). I might be laughed at for that, but arithmetic-based calculations tend to be easier.

$date = date('yyyy-mm-dd');

Ok so i fixed it lol. I saw the fail as i answered you mate. Thanks allot

php for today in Mysql format is date("Y-m-d");
mysql for today is CURRENT_DATE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.