MySQL problems... Is this my fault or a server thing?!

Post test messages here

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
magician13134
 
Posts: 1119
Joined: Wed Jun 13, 2007 9:17 am

MySQL problems... Is this my fault or a server thing?!

Post by magician13134 »

Code: Select all

<?php
	$articleId=$_GET['viewArticle'];
	if(!isset($articleId)){$articleId=1;}
	$articleId=(int)$articleId;
	if(isset($_GET['reportPost'])){
		$commentId=(int)$_GET['reportPost'];
		$result=mysql_query("SELECT * FROM `comments` WHERE id=$commentId");
		if($row=mysql_fetch_array($result)){
			mysql_query("UPDATE `comments` SET `content`=content + 1 WHERE `id`='$commentId' LIMIT 1");
			$result=mysql_query("SELECT * FROM `comments` WHERE id=$commentId");
			if($row=mysql_fetch_array($result)){
				echo "<script>alert('".$row['content']."');</script>";
			}
		}
		echo "<script>document.location='index.php?viewArticle=$articleId#comment$commentId';</script>";
	}
?>
I know the code ONLY runs once since it echos an alert every time it runs, and that only happens once... The problem is that the field is incremented by a huge number every time this is run. The same thing happened with I read the field value in PHP, incremented it in PHP and the set it to the (IE, '$content' instead of 'content + 1')... I have no idea what's going on! I feel this is a deeper error than something on my part... Am I correct in assuming that?

SolidSilver
 
Posts: 65
Joined: Sat Mar 31, 2007 11:29 am

Re: MySQL problems... Is this my fault or a server thing?!

Post by SolidSilver »

magician13134 wrote:

Code: Select all

mysql_query("UPDATE `comments` SET `content`=content + 1 WHERE `id`='$commentId' LIMIT 1");
That works fine as a bare statement in phpmyadmin. It's possible you need to backtick both occurrences of 'content'.

Locked
Please be positive and constructive with your questions and comments.

Return to “Test Message Forum (closed)”