Really Simple Php Form To Save To A Text File
<p>I found a code here for saving a form to a text file. The problem is that it doesn't save the form to <code>/tmp/mydata.txt</code>. It says "xxx bytes written" but when I open the txt file I can't see the values I submitted.</p>

<p>Also what should I do to save the txt filenames dynamically like <code>datesubmitted.txt</code> for example.</p>

<pre><code>&lt;form action="myprocessingscript.php" method="POST"&gt;
&lt;input name="field1" type="text" /&gt;
&lt;input name="field2" type="text" /&gt;
&lt;input type="submit" name="submit" value="Save Data"&gt;
&lt;/form&gt;

&lt;?php
if(isset($_POST['field1']) &amp;&amp; isset($_POST['field2'])) {
    $data = $_POST['field1'] . '-' . $_POST['field2'] . "\n";
    $ret = file_put_contents('/tmp/mydata.txt', $data, FILE_APPEND | LOCK_EX);
    if($ret === false) {
        die('There was an error writing this file');
    }
    else {
        echo "$ret bytes written to file";
    }
}
else {
   die('no post data to process');
}
</code></pre>