title: How to write data to a file with file_put_contents() without overwriting it?
body: <p>I'm to create a <code>txt</code> file with a list of names, those names come from a form.</p>
  
  <p>My logic goes as follows:</p>
  
  <pre><code>if ($_SERVER['REQUEST_METHOD'] == "POST") {
      $name = $_POST['username'];
  }
  
  
  function add_name($name, $file_name = "names.txt") {
      if(file_exists($file_name)) {
          $name = $name;
          file_put_contents($file_name, $name);
  } else { 
           $handle = fopen($file_name, 'w+');
           fwrite($handle, $name);
           fclose($handle);
      }
  }
  </code></pre>
  
  <p>Now problem is, it writes the name, however when I set another record, it deletes the previous, any help? maybe <code>file_put_contents</code> is not the right function to use?</p>