title: Writing post values to a text file
body: <p>I am trying to append a string to a text file.</p>
  
  <p>The file <code>users.txt</code> is in the same folder as the php file.</p>
  
  <pre><code>$fname=$_POST['fname'];
  
  $message = "name is :" . $fname. "\n";
  if (isset($_POST['submit'])) {
      if ( file_exists("users.txt")) {
          $fp = fopen ("users.txt", "a");
          fwrite($fp, $message);
          fclose($fp);
      } else {
          echo'&lt;script type="text/javascript"&gt;alert("file does not exist")&lt;/script&gt;';
      }
  }
  </code></pre>
  
  <p><strong>It is not throwing the message error, nor is it writing to the file</strong>.<br>
  What have I done wrong?</p>
  
  <p>My form:</p>
  
  <pre><code>&lt;form onsubmit="return ValidateInputs();" action="contact.php" method="post"  id="contactForm" &gt;
            &lt;input class="input" type="text"  name="fname" id="fname"  /&gt;
            &lt;input    type="submit" value="submit" name="submit"  /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>nb. this form does submit.. it will send the message to me in an email.</p>