0

This is what I have right now:

<?php           
if(isset($_POST['textdata']))
{
$data=$_POST['textdata'];
$fp = fopen('data.txt', 'a');
fwrite($fp, $data);
fclose($fp);
}
?>

It prints the submitted data in the same line inside the txt file, one big line without spaces.

So :

  1. how do I set new line inside the txt file for each form submit

  2. how to redirect to specific url after submit

I was trying form action="http://" and it redirects, but doesn't print to the file.

Thanks.

GMB
  • 216,147
  • 25
  • 84
  • 135
lt_J
  • 3
  • 2
  • I was browsing and checking before I posted my question; I couldn't use them because I didn't know how to integrate all together when it wasn't the code I currently use. PHP is not me, I felt the need to ask both questions in one thread with my own script. – lt_J Dec 16 '18 at 02:51

1 Answers1

0

You need a newline after data. Then use the PHP header() function to redirect.

You could use "\r\n" as the newline but I like PHP_EOL:

<?php           
if(isset($_POST['textdata']))
{
$data=$_POST['textdata'];
$fp = fopen('data.txt', 'a');
fwrite($fp, $data . PHP_EOL);
fclose($fp);
header("Location: http://www.yoursitehere.com");
}
?>
lufc
  • 1,965
  • 2
  • 15
  • 19