Save PHP form in file

With php you can store data, save php form in text file such as notepad and even in microsoft word too.
The following php code will make you able to store form data in microsoft word file. It will create ms word file too that if file is not created before.

  1. <?php
  2. $username = $_POST['username'];
  3. $fp = fopen("myfile.doc","a+") or exit("unable to open the file");
  4. if($fp != null)
  5. {
  6. fwrite($fp,$username);
  7. }
  8. fclose($fp);
  9.  
  10. ?>



And another example to save php form to a txt file:

  1. <?php
  2. $saving = $_REQUEST['saving'];
  3. if ($saving == 1){
  4. $data = $_POST['data'];
  5. $file = "data.txt";
  6.  
  7. $fp = fopen($file, "a") or die("Couldn't open $file for writing!");
  8. fwrite($fp, $data) or die("Couldn't write values to file!");
  9.  
  10. fclose($fp);
  11. echo "Saved to $file successfully!";
  12. }
  13. ?>
  1. <form name="form1" method="post" action="index2.php?saving=1">
  2. <textarea name="data" cols="100" rows="10">
  3. Vehicle #:
  4. RO #:
  5. Date:
  6. Tech Assigned:
  7. Warranty:
  8. Current Status:
  9. Comments:
  10. ———————————————
  11. </textarea>
  12. <br>
  13. <input type="submit" value="Save">
  14. </form>
  15. <p>
  16.  
  17. <a href="http://www.videoboob.com/holly/data.txt"><b>VIEW<b></a>

No related php tutorials.

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark
tabs-top

Leave a Reply