title: How To Make input Fields in HTML save into a txt or html file using PHP
body: <p>So for a few days now i have been looking through forum posts on how to make this work. I have found many post that were helpful. And had working Answers, but every time i tried it it didn't want to work for me. Now most of these post i saw were 2-5 years old. So i though to make a new one i thought to make a new one also since i don't really know any php, but i am trying to learn and so adapting the php is quite hard since i really know how to read it. so here is my code and some pics, also the links to the post i have looked at.BTW this is for a wiki project for a game called World At Arms, go check it out it is fun.</p>
  
  <p>HTML Code:</p>
  
  <pre><code>&lt;form action="totxt.php?saving=1" id="contact_form" method="post"&gt;
      First Name:
      &lt;input type="text" name="first" id="first" value="First Name" onblur="if(this.value == '') { this.value = 'First Name'; }" onfocus="if(this.value == 'First Name') { this.value = ''; }" /&gt;
      &lt;br /&gt; Last Name:
      &lt;input type="text" name="last" id="last" value="Last Name" onblur="if(this.value == '') { this.value = 'Last Name'; }" onfocus="if(this.value == 'Last Name') { this.value = ''; }" /&gt;
      &lt;br /&gt; In Game Name:
      &lt;input type="text" name="ing" id="ign" value="In Game Name" onblur="if(this.value == '') { this.value = 'In Game Name'; }" onfocus="if(this.value == 'In Game Name') { this.value = ''; }" /&gt;
      &lt;br /&gt; Current Level:
      &lt;input type="text" name="level" id="level" value="Current Level" onblur="if(this.value == '') { this.value = 'Current Level'; }" onfocus="if(this.value == 'Current Level') { this.value = ''; }" /&gt;
      &lt;br /&gt; Glory:
      &lt;input type="text" name="glory" id="glory" value="Glory" onblur="if(this.value == '') { this.value = 'glory'; }" onfocus="if(this.value == 'glory') { this.value = ''; }" /&gt;
      &lt;br /&gt; Message:
      &lt;br /&gt;
      &lt;textarea name="message" id="message" rows="10" cols="50"&gt;&lt;/textarea&gt;
      &lt;br /&gt;
      &lt;input value="Submit" type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>So This is the Html code i have smashed together from post i have found. it is messy and i'm pretty sure there are some chucks that can be taken away but i'm no coding mastermind.</p>
  
  <p>The PHP Code i have gathered together:</p>
  
  <pre><code>&lt;?php
  $first = $_POST["first"];
  $last = $_POST["last"];
  $ign = $_POST["ign"];
  $level = $_POST["level"];
  $glory = $_POST["glory"];
  $message = $_POST["message"];
  $text = "NAME: $first    $last &lt;br&gt;
  In Game Name: $ign&lt;br&gt;
  Current Level: $company&lt;br&gt;
  Glory: $glory&lt;br&gt;    
  MESSAGE: $message&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;";
  $file = "data.txt";
  $fp = fopen($file, "a") or die("Couldn't open $file for writing!");
  fwrite($fp, $text) or die("Couldn't write values to file!"); 
  fclose($file);
  ?&gt;
  &lt;meta http-equiv="refresh" content="0; url=Success.html" /&gt;`
  </code></pre>
  
  <p>So this is the error i get when i hit submit:</p>
  
  <blockquote>
    <p>Couldn't open data.txt for writing!</p>
  </blockquote>
  
  <p>The links i used to get this far.<br />
  1: <a href="https://stackoverflow.com/questions/2009631/get-user-input-from-form-write-to-text-file-using-php">Get user input from form, write to text file using php</a><br />
  2: <a href="https://forums.digitalpoint.com/threads/save-php-form-data-to-a-txt-file.757223/" rel="nofollow noreferrer">https://forums.digitalpoint.com/threads/save-php-form-data-to-a-txt-file.757223/</a><br />
  3: <a href="https://stackoverflow.com/questions/14998961/php-write-file-from-input-to-txt">PHP write file from input to txt</a><br />
  4: There was another one but i cant seem to find the link.</p>