Location: PHPKode > projects > Oriblog > oriblog/newcomment.php
<?php

// include our db settings
include "db.inc";
// check we have a valid post to work with
$post = $_GET["post"];
if ($post != "" && is_numeric($post)) {
	// check if we have a valid parent comment to work with
	if ($parent != "" && is_numeric($parent)) {
		$result = mysql_query("SELECT * FROM comments where entry=$post and id=$parent",$db);
	}
	$result2 = mysql_query("SELECT title, entry FROM entries where id=$post");
	// display the post and the comment we're replying to (if any)
	if (mysql_numrows($result2)!=0) {
		$entry = mysql_fetch_array($result2);
		echo "<h1>".$entry["title"]."</h1><p>".$entry["entry"]."</p>\n<hr />\n";
		if ($parent !="" && is_numeric($parent)) {
			$myrow = mysql_fetch_array($result);
			echo "<!-- comment ".$myrow["id"]." -->\n<p>Comment posted by ".$myrow["poster"]."</p><p>".$myrow["comment"]."</p>\n";
		}
// provide an input form to get the user's comments
?>
<form action="postcomment.php" method="post">
	<table>
	  <tr>
	    <td>Name:</td>
	    <td><input type="text" name="name" size="50"><br />&nbsp;</td>
	  </tr>
	  <tr>
	    <td>Comment:</td>
	    <td><textarea cols="50" rows="7" name="comment"></textarea></td>
	  </tr>
	</table>
	<input type="hidden" name="post" value="<?php echo($post);?>">
	<?php
	if ($parent != "" && is_numeric($parent)) {
		echo "<input type='hidden' name='parent' value='".$parent."'>";
	}
	?>
	<p><input type="submit" value="Submit"></p>
</form>
<?php
	// if we got fed a duff post reference, say so
	} else {
	echo "Invalid post reference";
	}
// if we didn't get a reference at all, or it was otherwise duff, say so
} else {
echo "No post reference was provided, or an invalid post reference was provided.";
}
?>
Return current item: Oriblog