2017-07-15 37 views
0

我做了这个网站,http://mihaialin793.esy.es/new-homepage/portofolio/physics/,它有一个评论表。问题是,当我按提交时,在11条评论之后,HTML变得混乱,最后的评论被隐藏或删除,我无法弄清楚。经过11条评论,PHP不断丢失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

的 'FREAD' 方法仅输出1024字节在你的情况。

而是尝试使用:

echo "<h2 class='other_comm'>Other comments</h2>".fread($read, filesize('comment.txt')); 
+0

谢谢,我知道我在PHP中的小白。 –

+0

不用担心。它可以免费学习:-)。祝你的项目好运! – robinl