la faccio breve raga, io ho questo codice:
Codice PHP:
<?php
$datafile = "commenti.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);
}
?>
[b]Commenta:[/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%">Username:</td>
<td width="69%"><input type="text" name="name"></td>
</tr>
<tr>
<td width="31%">Commento:</td>
<td width="69%"><textarea name="comments" rows="3"></textarea></td>
</tr>
</table>
<input type="submit" name="submit" value="Commenta">
<input type="reset" name="Reset" value="Cancella">
</form>
<hr>
<?php
if (file_exists($datafile)) {
$read_data = file($datafile);
$num_comments = count($read_data);
for($c=0;$c<$num_comments-1;$c++){
$content = explode("::", $read_data[$c]);
echo "[b]Username:[/b] $content[0]";
echo "
";
echo "[b]Commento:[/b] $content[1]";
echo "
";
}
}
?>
<hr>
che inserisce commenti nella pagina stessa in cui il codice è presente.. però ogni volta che aggiorno la pagina, il commento precedentemente inserito si inserisci di nuovo da solo! come risolvo?