title: Write in a .txt File from a form in PHP
body: <p>I saw <a href="https://stackoverflow.com/questions/14998961/php-write-file-from-input-to-txt">this question</a> and I wanted to ask a question in the comment but didn't have enough reputation. So I'm asking the question here.</p>
  
  <p>I have a form in HTML:</p>
  
  <pre><code>&lt;form action="myprocessingscript.php" method="POST"&gt;
  Name : &lt;input name="field1" type="text" /&gt;
  Email : &lt;input name="field2" type="text" /&gt;
  &lt;input type="submit" name="submit" value="Save Data"&gt;
  </code></pre>
  
  <p>And a processing script in php, <code>myprocessingscript.php</code> :</p>
  
  <pre><code>if (isset($_POST['field1']) &amp;&amp; isset($_POST['field2'])) {
    $data = 'comments.txt' . $_POST['field1'] . ' ' . $_POST['field2'] . "\n";
    $ret = file_put_contents('comments.txt', $data);
  
    if ($ret === false) {
      die('There was an error Sending The Comment');
    } 
  
    else {
      echo "The Comment Has Been Sent Succesfully !";
    }
  } 
  
  else {
    die('Fill in The Form Please !');
  }
  
  if (isset($_POST['field1']) &amp;&amp; isset($_POST['field2'])) {
    $data = 'comments.txt' . $_POST['field1'] . ' ' . $_POST['field2'] . "\n";
    $ret = file_put_contents('comments.txt', $data);
  
    if ($ret === false) {
      die('There was an error Sending The Comment');
    } 
  
    else {
      echo "The Comment Has Been Sent Succesfully !";
    }
  } 
  
  else {
    die('no post data to process');
  }
  </code></pre>
  
  <p>When I write something in the form to a text file (comments.txt) the previous text is deleted - what should I do?</p>