0

I want my code to write every order into a seperated, new line, but it is not working right now with my code. Can someone explain me that what i am doing wrong?

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Rendelési eredmények</title>
    <link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
    <script src="main.js"></script>
</head>
<body>
    <h1>Rendelési eredmények: </h1>
</body>
</html>
<?php
    $abroncs_db = $_POST['abroncs_db'];
    $olaj_db = $_POST['olaj_db'];
    $gyertya_db = $_POST['gyertya_db'];
    @$fp = fopen("C:\\wamp64\\www\\bob\\rendelesek.txt", 'ab');
    $datum = date('H:i jS F Y');
    #$honnan_hallott_rolunk = $_POST['honnan_hallott_rolunk'];
    $osszmennyiseg = $abroncs_db + $olaj_db + $gyertya_db; 
    $szallitasi_cim = $_POST['szallitasi_cim'];
    define('ABRONCSAR', 100);
    define('OLAJAR', 10);
    define('GYERTYAAR', 4);

    if ($osszmennyiseg == 0) {
        echo '<p class="warning">Ön egyetlen tárgyat sem rendelt az előző oldalon.</p>';
    } else {
    echo "<p>Rendelés feldolgozásának időpontja: ".date('H:i jS F Y')."</p>";
    /* if ($honnan_hallott_rolunk == "a") {
        echo 'Ön visszatérő vásárló Bobnál.';
    } else if ($honnan_hallott_rolunk == "b") {
        echo 'Ön internetes hirdetés útján talált rá Bobra.';
    } else if ($honnan_hallott_rolunk == "c") {
        echo 'Ön tévéreklám által talált rá Bobra.';
    } else if ($honnan_hallott_rolunk == "d") {
        echo 'Ön egy ismerőse által hallott Bobról.';
    } */
    echo '<p>Rendelés összegzése: </p>';
    echo $abroncs_db.' darab gumiabroncs, <br/>';
    echo $olaj_db.' darab olaj, <br/>';
    echo $gyertya_db.' darab gyújtógyertya. <br/>';

    echo '<hr width="50" align="left">';
    $vegosszeg = ABRONCSAR * $abroncs_db +
    OLAJAR * $olaj_db +
    GYERTYAAR * $gyertya_db;
    echo 'Összesen: '.$osszmennyiseg.' darab tétel, amelyeknek ára '. $vegosszeg. "$." ;
    }
    $kimeneti_sztring = $datum."\t".$abroncs_db." gumiabroncs \t".$olaj_db." olaj\t"
    .$gyertya_db." gyújtógyertya\t\$".$vegosszeg."\t". $szallitasi_cim."\n";
    fwrite($fp, $kimeneti_sztring);
?>

I looked at many other forums which had a question like mine, but i could not find the good solution for this problem. If anyone could help me, thanks!

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • 1
    HTML after ` – user3783243 Nov 19 '18 at 19:56
  • 3
    You seem to have a mix of echoing out `
    ` and `\n`. Use `
    ` throughout and your content should all be on separate lines. Also, you really shouldn't be running `fopen()` on a local file (that won't work on servers), and you also might want to check that your `$_POST` data is set.
    – Obsidian Age Nov 19 '18 at 19:59
  • 1
    Use `PHP_EOL` instead of `"\n"` then it does not matter if this runs on Windows or Unix – RiggsFolly Nov 19 '18 at 20:09
  • 1
    ALso remember, if you move this to a unix server `C:\\wamp64\\www\\bob\\rendelesek.txt` wont exist. Instead use reletive paths like `'rendelesek.txt'` or `'bob/rendelesek.txt'` also use the unix `/` always, PHP will do all the conversion if it sees you on a Windows box – RiggsFolly Nov 19 '18 at 20:13

2 Answers2

0

Instead of using \n use <br /> to get new line in HTML document. If you want to show some .txt file you should also change \n to <br /> before put it to html document.

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345
0

I'm guessing you're opening the generated text file in Notepad on Windows?

Notepad expects Windows-style CRLF line-endings. You are only outputting a LF (\n).

To get Notepad to display the newlines, write \r\n to the file instead of just \n.

rickdenhaan
  • 10,857
  • 28
  • 37