Jump to content


Photo

Adding and viewing comments isn't working for me???


  • Please log in to reply
2 replies to this topic

#1 cturner

cturner
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • LocationMy computer

Posted 20 October 2006 - 09:50 AM

I am trying to add an articleid everytime a comment has been added to a database table then view the comments when an article has selected and it isn't working out for me. It isn't displaying every comments for the particular article. Can someone please help me solve this problem? Thanks in advance. ???

Here is the code for adding the articleid:
	$articleid = mysql_real_escape_string($_GET['articleid']);
	// get the user's username that made the comment
	$username = mysql_real_escape_string($_COOKIE['username']);
	// get the comment from the form
	$comment = mysql_real_escape_string($_POST['comment']);
	// get today's date
	$date_entered = date("j F, Y");
	$date = mysql_real_escape_string($date_entered);
	// insert the articleid into the commentpost table
	$insert = "INSERT INTO `commentpost` (`id`, `articleid`, `comment`, `date_entered`, `username`) VALUES (0, '$articleid', '$comment', '$date', '$username')";

		if (mysql_query ($insert)) {
			// once the data has been added go to the comment_added page
			header ('Location: comment_added.php');
		} else {
			print "<p>Could not add the entry because: <b>" . mysql_error() .
			"</b>. The query was $sql.</p>";
		}
mysql_close();

Here is the code for viewing the comments:
	$articleid = mysql_real_escape_string($_GET['articleid']);

	// select the articleid
	$query = "SELECT * FROM `commentpost` WHERE articleid = $articleid";
	$result = mysql_query ($query) or die("Could not query because: " . mysql_error());
		
	while($row = mysql_fetch_array($result)) {
		// print the comments for that article and the date entered and the username
		echo "<br /><br />".$row['date_entered']."<br />".$row['comment']."<br />";
		echo $row['username']."<br />";
	}
mysql_close();


#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 20 October 2006 - 11:41 AM

Please show the commentpost table scheme!

me!

#3 cturner

cturner
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • LocationMy computer

Posted 20 October 2006 - 09:29 PM

Commentpost (id, articleid, comment, date_entered, username)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users