Menu

How to view form data in an Excel file

Help
hanniella
2008-04-28
2013-06-03
  • hanniella

    hanniella - 2008-04-28

    I want data from the form to be sent into an Excel file but I am a bit of a beginner and need a bit of guidance.  I know I must create a file in my private directory and link to this in proessor.php but what sort of file does this need to be and how do I create it? How do I view it with Excel? Any help would be much appreciated! Thanks in advance.

     
    • TNTEverett

      TNTEverett - 2008-04-29

      Excel will open a Comma Separated File (name.csv) by double click.  A simple example below.

      Create a file where the first line looks like this:
      First Name:,Last Name:,Address:,Grade Level:

      THen add code like this to the processor.php file:
      $fileLine = $_POST['field_1'] . "," . $_POST['field_2'] . "," . $_POST['field_3'] . "," . $_POST['field_4'] . "\r\n";

      $filename = './files/Data.csv';
      if (is_writable($filename)) {

                      if (!$handle = fopen($filename, 'a'))
                      {
                           echo "Cannot open file ($filename)";
                           exit;
                      }
                      if (fwrite($handle, $fileLine) === FALSE) {
                          echo "Cannot write to file ($filename)";
                          exit;
                      }

                      fclose($handle);

                  } else {
                      echo "The file is not writable";
                  }

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.