0

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>>>>
4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by tiggsy
0

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.

1

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.

0

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');

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.