I just threw together a little commenting system. But, I think it might be kind of onorthodox. For the submitted comment I'm using $_SERVER['SCRIPT_NAME'] and storing it as a varchar. Then, if the recorded location/varchar of the comment matches the current active page, the comments are displayed. Is this a good way to do this? What other ways would there be to approach this? Thank you.
<?php
require('inc/connect.inc.php');
require('inc/core.inc.php');
?>
<form action="<?php echo $current_file; ?>" method="post">
<input type="hidden" name="page" />
Name:<br /><input type="text" name="name" /><p>
Comment:<br /><textarea rows="8" cols="45" name="comment"></textarea><p>
<input type="submit" value="submit" />
</form>
<?php
$page_on = $_SERVER['SCRIPT_NAME'];
if(isset($_POST['page'])&&isset($_POST['name'])&&isset($_POST['comment'])) {
$page = $_POST['page'];
$name = $_POST['name'];
$comment = $_POST['comment'];
$page = $_SERVER['SCRIPT_NAME'];
if(!empty($page)&&!empty($name)&&!empty($comment)) {
$query = mysql_query("INSERT INTO comments VALUES ('','".mysql_real_escape_string($name)."','".mysql_real_escape_string($comment)."','".mysql_real_escape_string($page)."')");
}
}
echo '<br /><br />';
$result = mysql_query("SELECT * FROM comments ORDER BY id DESC");
while($row = mysql_fetch_assoc($result)) {
$name = $row['name'];
$comment = $row['comment'];
$currentfile = $row['currentfile'];
if($page_on==$currentfile) {
echo $name.'\'s comment:<br />'.$comment.'<p>';
}
}
?>
SCRIPT_NAMEwould be/.../article2157.phpor something?