Form to CSV capture

Discussion in 'Programming' started by wizs, Jul 20, 2009.

  1. #1
    Hello,

    I am looking for some advice and would appreciate any pointers that you programmers could provide!

    I want to set up a system where I can create any number of forms on my website, then capture the information from them into a CSV file (e.g. name, address, and perhaps other fields).

    Is this possible? Is it a big job or do you think me (with quite limited PHP knowledge) could do this with a little research?

    Thanks!
     
    wizs, Jul 20, 2009 IP
  2. adrevol

    adrevol Active Member

    Messages:
    124
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Helo wizs,

    You can do it your self with little research .

    Here is sample code which can help you in writing the form text into csv files on your server.
    But before that, make sure your file names are secure and path to csv files are secure and other issues
    
    $filename= "test.csv";
    $somecontent = "\"100\",\"Nagendra Kumar & testing for thie asdf \\nadfasas \",\"1087\"\n";
    
    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {
    
        // In our example we're opening $filename in append mode.
        // The file pointer is at the bottom of the file hence
        // that's where $somecontent will go when we fwrite() it.
        if (!$handle = fopen($filename, 'a')) {
             echo "Cannot open file ($filename)";
             exit;
        }
    
        // Write $somecontent to our opened file.
        if (fwrite($handle, $somecontent) === FALSE) {
            echo "Cannot write to file ($filename)";
            exit;
        }
    
        echo "Success, wrote ($somecontent) to file ($filename)";
    
        fclose($handle);
    
    } else {
        echo "The file $filename is not writable";
    }
    
    Code (markup):

    By this way, you can append text to your csv file ..

    capture your form content and make the content as escaped and seperated with commas and do the further appending ..

    Hope this will helps u
     
    adrevol, Jul 20, 2009 IP
  3. wizs

    wizs Active Member

    Messages:
    72
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    63
    #3
    Thanks for the reply I will have a look and see if I can figure it out!
     
    wizs, Jul 20, 2009 IP