ok ok ho trovato l'errore per il fatto che non fa vedere l'ultimo.
Eccoti tutto il codice corretto.
Codice PHP:
<?php
$datafile = "files/data.txt";
if(isset($_POST['submit'])){
$name = $_POST['name'];
$comments = $_POST['comments'];
$new_content = "$name::$comments\n";
$fp = fopen($datafile, "a");
$fw = fwrite($fp, $new_content);
$fc = fclose($fp);
header("Location: ".$_SERVER['PHP_SELF']."");//aggiunta
}
?>
<html>
<body bgcolor="#FFFFFF" text="#000000">
[b]GUESTBOOK [/b]
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?> ">
<table width="30%" border="0" cellspacing="0" cellpadding="0" height="50">
<tr>
<td width="31%">Name:</td>
<td width="69%"><input type="text" name="name"></td>
</tr>
<tr>
<td width="31%">Comments:</td>
<td width="69%"><textarea name="comments" rows="3"></textarea></td>
</tr>
</table>
<input type="submit" name="submit" value="Submit Comment">
<input type="reset" name="Reset" value="Reset">
</form>
<hr>
<?php
if (file_exists($datafile)) {
$read_data = file($datafile);
$num_comments = count($read_data);
for($c=0;$c<$num_comments;$c++){//prima era for($c=0;$c<$num_comments-1;$c++){
$content = explode("::", $read_data[$c]);
echo "[b]Name:[/b] $content[0]";
echo "
";
echo "[b]Comment:[/b] $content[1]";
echo "
";
}
}
?>
<hr>
</body>
</html>
Provato e funzionanate. Io aggiungerei giusto un controllo per vedere se quello passato dal posto non sia già presente nel file in modo da evitare doppi post uguali.