Page 1 of 1

everything is updated...help!

Posted: Tue Mar 22, 2005 4:07 am
by pleigh
i have a script that edit the content the comment and updates the database....

Code: Select all

<?
			$cid = $_GET['cid'];
			
			if (isset($_POST['submit']))
			{
				$message = NULL;
			
				if (empty($_POST['comment']))
				{
					$c = FALSE;
					$message .= 'Please enter your comment!<br>';
				}
				else
				{
					$c = addslashes($_POST['comment']);
				}
			
				$updatequery = "UPDATE posts SET postupdate=NOW() WHERE postID='".$cid."'";
				$updateresult = @mysql_query($updatequery);
				
				$query = "UPDATE comments SET comment='$c' WHERE postID='".$cid."'";
				$result = @mysql_query($query);
			
				if ($updatequery && $result)
				{					
					echo '<b/>Your comment has been posted!';
					echo '<meta http-equiv="refresh" content="3;url=http://localhost/mysample/report.php">';
					exit();
				
				}
				else
				{
					echo 'Your comment cannot be posted due to system error!'.mysql_error();
				}
				//mysql_close();
			}
		
			if (isset($message))
			{
				echo '<font color="red">', $message, '</font>';
			}
			?>
my problem is that, when there are two or more comments, then i want to update one comment, all the comments are updated....

Posted: Tue Mar 22, 2005 4:17 am
by CoderGoblin
Do you have a commentID. I take it postid is the same for all comments being changed. You need to restrict the SQL update to the specific comment.

Posted: Tue Mar 22, 2005 4:22 am
by pleigh
thanks coder...i also think that i should include the commentID with the postID....lots of thanks....

Posted: Tue Mar 22, 2005 4:22 am
by n00b Saibot
This will definitely update all the comments made to a post, since you are updating the comments by PostID and *not* by CommentID as it should be. Post the commentID from the Edit Comment page and use that to update the comments. Simple!

EDIT: Uh oH, beaten by vast margin :lol: