我创建了这个网站http://mihaialin793.esy.es/new-homepage/portofolio/physics/,其中有一个评论表单。问题是,当我按下提交时,在11条评论之后,HTML变得混乱,最后的评论被隐藏或删除,我无法弄明白。
PHP代码:
<?php
if($_POST['submit']){
print "<h1>Your comment has been sent!</h1>";
$name = $_POST['name'];
$comment = $_POST['message'];
#Get old comments
$old = fopen("comment.txt", "r+t");
$old_comments = fread($old, 1024);
#Delete everything, write down new and old comments
$write = fopen("comment.txt", "w+");
$string = "<div class='comment'><span class='name'>".$name.":</span><span class='comm'>".$comment."</span></div><br>\n".$old_comments;
fwrite($write, $string);
fclose($write);
fclose($old);
header('Location: index.php');
}
#Read comments
$read = fopen("comment.txt", "r+t");
echo "<h2 class='other_comm'>Other comments</h2>".fread($read, 1024);
fclose($read);
?>
html在网站上,但我也会在这里告诉他们:
HTML:
<form action="" method="post">
<h2>Post your comment</h2>
<input type="text" name="name" placeholder="Name" required><br />
<textarea name="message" placeholder="Comment"></textarea><br />
<input type="submit" name="submit" value="Post">
</form>
答案 0 :(得分:0)
'fread'方法在你的情况下只输出1024个字节。
而是尝试使用:
echo "<h2 class='other_comm'>Other comments</h2>".fread($read, filesize('comment.txt'));