how to save html form details into a textfile by hitting the submit key.help me...

by 5 replies
7
how to save html form details into a textfile by hitting the submit key.help me...
#programming #details #form #hitting #html #keyhelp #save #submit #textfile
  • Well...here's the quick answer, assuming use of php, and that you know a little about this:

    1. On the form target page, gather the submitted form data into a single string variable, formatted as you'd like to see it.
    2. use fopen() to open a writeable file
    3. use fwrite() to write the string to the opened file.
    4. use fclose()...just to keep things tidy.

    If you need more detail...I've been intending to write some basic php articles on my site. This might as well be the first one. Let me know if you'd like to see it.
    • [1] reply
    • can you give php codes..please friend....
  • Here's the code you need...

    It assumes that the "name" of the submit button is "submit". If this is not the case, you need to change either the name of the submit button or the name of the $_POST['submit'] to match up.

    The only other thing you need to do is to name the $filename what you want the filename to be. If you want the file placed in a directory, say submissions/filename.txt, then you need to include that in your filename ($filename = 'submissions/filename.txt'

    If you need help, let me know...

    <?php
    if(isset($_POST['submit'])) {
    $filename = 'filename.txt';
    $fp = @fopen($filename, 'w');
    foreach($_POST AS $key=>$data) {
    @fwrite($fp, $data."\r\n");
    }
    @fclose($fp);
    }
    ?>
    • [1] reply
    • @Big squid Thanks for the good code information.
      For more details just refer the following link
      Tizag.com/phpT/filewrite.php
      • [1] reply

Next Topics on Trending Feed