All pastes #433845 Raw Edit

Comment editting

public php v1 · immutable
·published 2007-04-11 01:06 UTC
rendered paste body
		//Current time/date originally NOW()		$rightnow = date('D. dS \of F Y g:i:s A');		//Add slashs to entry to make sure it doesn't mess with the mysql		//$entry = nl2br ($_POST['entry']);		$entry = $_POST['comment']; //Replaces the old nl2br here, as we will only nl2br when we showt the post on a page		$entry = mysql_real_escape_string ($entry);		//Define the query		if ($_post['pid_hidden'] == $_POST['pid'] OR !is_numeric($_POST['pid'])) //If the post id was not modified or was not a number		{			if ($_post['username_hidden'] == $_post['username']) //If the username was the same as before			{				if ($_post['comment_hidden'] == $_post['comment']) //If the comment was the same as before				{					$update = "false"; //Don't update, there's nothing to update!				}				else //We need to update the comment only				{					$query = "UPDATE blog_comments set comment='$entry' WHERE cid={$_POST['id']}";				}			}			else //Well, we need to update at LEAST the username!			{				if ($_post['comment_hidden'] == $_post['comment']) //If the comment was the same as before				{					$query = "UPDATE blog_comments SET username='{$_POST['username']}' WHERE cid={$_POST['id']}";				}				else //this means we need to update both the username and the comment itself				{					$query = "UPDATE blog_comments SET username='{$_POST['username']}', comment='$entry' WHERE cid={$_POST['id']}";				}			}		}		else //We at LEAST need to update the pid		{			if ($_post['username_hidden'] == $_post['username']) //if the username is the same, don't update it			{				if ($_post['comment_hidden'] == $_post['comment']) //If the comment was the same as before				{					$query = "UPDATE blog_comments SET pid={$_POST['pid']} WHERE cid={$_POST['id']}"; //upate ONLY the pid				}				else //if we also need to update the comment itself				{					$query = "UPDATE blog_comments SET pid={$_POST['pid']} , comment='$entry', pid={$_POST['pid']} WHERE cid={$_POST['id']}";				}			}			else //Here we need to update at LEAST the pid and the username			{				if ($_post['comment_hidden'] == $_post['comment']) //If the comment was the same as before				{					$query = "UPDATE blog_comments SET SET username='{$_POST['username']}', pid={$_POST['pid']} WHERE cid={$_POST['id']}";					//We update everything except the comment				}				else //We update everything here!!!! :-D				{					$query = "UPDATE blog_comments SET username='{$_POST['username']}', comment='$entry', pid={$_POST['pid']} WHERE cid={$_POST['id']}";				}			}		}		$r = mysql_query ($query); //Execute the query		//Report on the result		if (!$update) //No need to update if this isn't set to true		{			if (mysql_affected_rows() == 1)			{				print '<p>The comment has been updated</p>';			}			else			{				print "<p>Could not update the comment because <b>" . mysql_error() . "</b>. The query was $query";			}		}		else //This means it needs no updating		{			print "<p>Either you're not updating anything at all, or the pid you entered wasn't a valid number</p>";		}