Jump to content


Photo

The comments aren't displaying???


  • Please log in to reply
3 replies to this topic

#1 cturner

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

Posted 21 October 2006 - 03:32 AM

After adding a comment I try to view the comment and it just displays a blank page. Can someone please tell me why and how I can fix? Thanks in advance.

Here is the code to add a comment:
require "config2.php";
$arrErrors = array();

// the publish button
if (isset($_POST['publish'])) {
	// if comment field is empty display a message
	if ($_POST ['comment'] == '') {
		$arrErrors['comment'] = 'Please enter a comment.';
	}

// if no errors insert data into database
if (count($arrErrors) == 0) {
	// get the id number
	$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 $insert.</p>";
		}

} else {
	// The error array had something in it. There was an error.
    // Start adding error text to an error string.
    $strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>';
    // Get each error and add it to the error string
    // as a list item.
    foreach ($arrErrors as $error) {
		$strError .= "<li>$error</li>";
	}
    $strError .= '</ul></div>';
	}
}

Here is the code to view the comments:
require "config2.php";
	$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 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 21 October 2006 - 11:40 AM

try checking to see how much rows you are getting:
echo "Rows Found: ".mysql_num_rows($query);

Good luck with your coding.
Jason / ProjectFear / Jaysonic

#3 cturner

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

Posted 21 October 2006 - 09:34 PM

I have placed that into my code to view the comments and it displays 0 rows. What I am wanting to know is why does it displays 0 rows when I have just added a comment for that article?

#4 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 22 October 2006 - 06:20 AM

try echoing out $articleid and see if it is actually set. if it is set then go into phpMyAdmin and view the comments table and look for the record you just added. check that the articleid matches the one in your link.
Good luck with your coding.
Jason / ProjectFear / Jaysonic




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users