Forum Moderators: coopster
<?php
//print title
echo '<h3>Comment On This Article</h3><br />';
//print form
echo "<form method=\"POST\" name=\"comment\" action=\"save_cmt.php?art=$art\">
Name<br><input type=\"text\" name=\"name\" size=\"20\"><br>
Comment<br><textarea name=\"comment\" rows=\"5\" cols=\"20\"></textarea><br />
<input class=\"button\" type=\"submit\" name=\"submit\" value=\"OK\">
</form>";
//get article name- testing only
//$art = $_GET['art'];
//$_POST['submit'] == false;
//change file extension to .cmt, thats the format we have used for the comment file
$comment_file = str_replace('txt', 'cmt', $art);
//if comment file exists, read and print comments
if (file_exists($comment_file))
{
$file_array = file($comment_file);
//echo $file_array;
foreach($file_array as $line)
{
$line_array = explode("¦", $line);
echo '<strong>'.$line_array[0].'</strong>'.'<br/ >';
echo '<font class="date">'.$line_array[1].'</font>'.'<br/ >';
echo '<i>'.$line_array[2].'</i>'.'<br/ ><br />';
}
}
else
{
echo 'no comments';
}
?>
and here is the save comment script...
<?php
if (!isset($_POST['name']) ¦¦ empty($_POST['name']) ¦¦!isset($_POST['comment']) ¦¦ empty($_POST['comment']) )
{
echo 'please fill in the form if you wish to comment';
} else
{
//echo $_POST['name'].'<br />';
//echo $_POST['comment'].'<br />';
$today = date("F j Y g:i a");
$name = $_POST['name'];
$comment = $_POST['comment'];
$art_file = $_GET['art'];
$comment_file = str_replace('.txt', '.cmt', $art_file);
//echo $art_file.'<br />';
//echo $comment_file.'<br />';
$content = $name.'¦'.$today.'¦'.$comment."\r\n";
//echo $content;
$fh = fopen($comment_file, 'a');
fwrite($fh, $content);
fclose($fh);
//header('Location: index.php?art=$art_file;');
echo 'comment has been added.';
echo $_SERVER['PHP_SELF'];
}
?>