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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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";
}