0

Trying to make my form inputs to be written in data.txt file. I want it to write in new line each time someone registers. Tried to use .PHP-EOL but it doesn't seem to add any new line after each entry!

<?php
 $path = 'data.txt';
 if (isset($_POST['firstname']) && isset($_POST['country']) && isset($_POST['email'])) {
    $fh = fopen($path,"a+");
    $string = $_POST['firstname'].' - '.$_POST['country'].' - '.$_POST['email'] .PHP_EOL;
    fwrite($fh,$string); // Write information to the file
    fclose($fh); // Close the file
 }
?>
naathanz
  • 21
  • 1
  • 6

1 Answers1

0

I got it to work!

Use PHP_EOL at the beginning instead of the end.

Here is the code now:

<?php
 $path = 'data.txt';
 if (isset($_POST['firstname']) && isset($_POST['country']) && isset($_POST['email'])) {
    $fh = fopen($path,"a+");
    $string = PHP_EOL .$_POST['firstname'].' - '.$_POST['country'].' - '.$_POST['email'];
    fwrite($fh,$string); // Write information to the file
    fclose($fh); // Close the file
 }
?>
naathanz
  • 21
  • 1
  • 6