Increment number of comments

Hello people

I have 2 tables in mySQL Database

Message, and MessageComment

I want add one on Message.numberOfComments each time some one post comment in the MessageComment table

Here is my try

[php]
$coment = sprintf(“UPDATE messages SET comentsNo=comentsNo+1 WHERE news_id =$colname_MessRc”);

mysql_select_db($database_cong, $cong);
$comentResult = mysql_query($coment, $cong) or die(mysql_error());

[/php]

[member=72276]QJK[/member]

What error are you getting?

I got this 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 '' at line 1

Are you sure the error is coming from that statement?

Anyway I would remove the sprintf

[php]$coment = “UPDATE messages SET comentsNo=comentsNo+1 WHERE news_id =$colname_MessRc”;[/php]

That is a mySQL error.

  1. I found the problem
 $coment = sprintf("UPDATE messages SET comentsNo=comentsNo+1 WHERE news_id =$colname_MessRc");
 	
 	mysql_select_db($database_cong, $cong);
 	$comentResult = mysql_query($coment, $cong) or die(mysql_error());

$colname_MessRc was declarer after the query, I put the $colname_MessRc before the query

Sponsor our Newsletter | Privacy Policy | Terms of Service