16-Jun-16
Hi, I have an HTML form with text, radio buttons, check boxes, and text area fields. I want to write all the fields into a CSV file. It is writing to the CSV file, but unfortunately if there is a comma in any of the fields, it moves the text after the comma to the next field.
I did some research and found I should use 'fputcsv'. All the examples that I found were getting their data from a database, and creating an array. I would like to know how to create an array from the data in my form so I can use it with 'fputcsv'. Below is a sample of my code.
// Create file. If file has been created, open file.
$myfile = fopen("ZZZmycsv.csv", "a") or die("Unable to open file!");
// Write to file.
// Column headers
$msg = "First Name, Last Name, Organization, Email, City, State, Comment 1, Comment 2
";
// Form variables
$msg .= "$firstName, $lastName, $organization, $email, $city, $state, $comment1, $comment2
";
Please be as detailed as possible with your answers.
Thanks in advance for your time and consideration.