Search code examples
phppostfopenfwrite

Fwrite solution rewrite PHP


So.. i have problems with this code :

$filename = "info.txt"; 
$tex = $_POST['Name']; 
$text = $tex . $_POST['Surname']; 
$fp = fopen ($filename, "w"); 
if ($fp) { 
fwrite ($fp, $text); 
fclose ($fp); 

It saves ONLY 1 name & surname. after another person submits his info, previous information is lost.

Is it possible to save all information?


Solution

  • You have to change the mode for fopen :

    change 'w' to 'a' (a for append)

    You'll find more information about each mode right here:

    https://www.php.net/manual/en/function.fopen.php#refsect1-function.fopen-parameters