0
<!doctype html>
<html>
  <body>
    <?php
    echo "<h3>your order is processed !!!!</h3> <br>";
    $akash = $_POST["tires"];
    $akash2 = $_POST["Oil"];
    $akash3 = $_POST["plugs"];
    $akash4 = $_POST["hello"];
    $write = "tires is  ".$akash."<br>" ."Oil is " .$akash2."\t" ."Spark plug is " .$akash3."\t". "address is  " .$akash4."<br>";
    $open = fopen("order.txt","ab");
    $write = fwrite($open,$write);
    ?>
  </body>
</html>
Unihedron
  • 10,902
  • 13
  • 62
  • 72
  • 1
    In what way are they not working? How are you displaying your resulting text file? – mario Sep 07 '14 at 05:49
  • `\t` is not html, `
    ` is html, if you open the file in browser you will get linebreaks, if you open it in notepad you propably get `tabs`. To linebrake in notepad you need `\n` or better use `\r\n`. Also, its not very important but..., you dont close the handle from `fopen`. And why are you overriding your string with the write-state ?
    – Dwza Sep 07 '14 at 05:57
  • tires is 4
    Oil is 2 litres Spark plug is 6 address is adam@yahoo.com
    This order was processed atSun Sep 2014 this is how my text file looks after i run my code
    – Akash Devgan Sep 07 '14 at 06:24
  • possible duplicate of [Create Carriage Return in PHP String?](http://stackoverflow.com/questions/15131619/create-carriage-return-in-php-string) – Jens A. Koch Sep 07 '14 at 15:47

2 Answers2

1

Try /r/n rather <br>(it's a html tag will not work with txt)

$write = "tires is  ".$akash."\r\n" ."Oil is " .$akash2."\t" ."Spark plug is " .$akash3."\t". "address is  " .$akash4."\r\n";
$open = fopen("order.txt","ab");
$write = fwrite($open,$write);
fclose($open);

in my case output is:-

tires is  sdff
Oil is ddddd    Spark plug is fffff address is  ggggg
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
0

you may want to drop the "b" in the fopen statement. From the manual , option b is "binary" which is probably causing the error.

Keith Grey
  • 151
  • 7