Page 1 of 1

UPDATE is updating something i didn't tell it to!

Posted: Sun Feb 02, 2003 2:06 am
by Sevengraff
Ok, im using MySQL. I've been working on a sorta light-weight CMS that lets me post articles and such. users can post comments on the articles, and it logs the date&time of it. but, when it adds a comment, it changes the time that the article was created, when it should only add to the number of comments.

here are my queries:

Code: Select all

// add comment to db

INSERT INTO `comments` ( `id` , `parent` , `author` , `email` , `comment` , `created` )
VALUES (
'', '$id', '$author', '$email', '$comment', NOW( )
);

SELECT * FROM articles WHERE id='$id'  // to get the count of comments on this perticuar article

UPDATE articles SET comments='$newcount' WHERE id='$id'  // and to update that count.
As you can see, the only UPDATE query affects the comments row, not the row where i keep the date & time. I dont understand why it changes it.
Any idea on why it affects the article?

try

Posted: Sun Feb 02, 2003 11:33 am
by AVATAr
try putting the date in a variable before you make the insert, and then insert using that variable (dont use NOW())... im guessing here.

Posted: Sun Feb 02, 2003 12:48 pm
by kcomer
I'm geusing you are using the filed type of timestamp for the date. Try useing the datetime field type. I belive the timstamp filed will get updated with the newest timestamp every time the record is modified, no matter what field. This should fix it for you.

Keith

Posted: Sun Feb 02, 2003 4:30 pm
by Sevengraff
ok, thanks kcomer, that was my problem. didn't realize that it would auto-change. i'll remember that from now on. thanks!