Trying to finish a comment system. Know where I want the comments shown, at the bottom of comment form, but am stuck on the comment.php. Not sure what I’m doing wrong. Any help is appreciated.
Code for comment.php:
<? $name = htmlspecialchars($_POST['name'], "Enter your name"); $email = htmlspecialchars($_POST['email']) $comments = htmlspecialchars($_POST['comments'], "Write your comments"); @$fp = fopen("comments.php", 'a'); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { $email = ''; } if (!$fp) { echo "There was an error! Please try again later!";} else { if(strlen($name) > 0 && strlen($message) > 0) { if(filesize('comments.php') > 0) { $pre = ','; } $outputstring =$pre "Welcome".$name.
.$comments. ; fwrite($fp, $outputstring, strlen($outputstring)); fclose($fp); Header("location:comment.html"); } ?>
Code for where I want comments shown:
<? @$fh = fopen('comments.php','r'); $comments = fread($fh,filesize('comments.php')); fclose($fh); $comments = explode(',',$comments); array_reverse($comments); if(filesize('comments.php') == 0) { echo "No comments"; } else { foreach($comments as $comment) { echo ($comment); } } ?>