everything is updated...help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

everything is updated...help!

Post 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....
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

thanks coder...i also think that i should include the commentID with the postID....lots of thanks....
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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:
Post Reply