HTML form data to CSV File using php code


I need help with a php code that can take the information from a filled out html form and send the info to a csv file in the background (or on the host site). Taking a basic form as provided and the function $_POST how can I write code that will take the input data and export it to a file. If you can provide just a basic example of how a csv file is filled out or called upon using other scripts would really be appreciated.


First name:

Last name:


#1 option
#2 option


Nick, a CSV file is just a text file with a different extension. Therefore you just have to write your data in the
format you want it in. Normally, it contains your field names in the top row or first line of the file. Depends on
how you are using them. Check out PHP.NET or W3Schools for writing text files.


[php]$_POST[‘fname’] = ‘Sam’;
$_POST[‘lname’] = ‘Smith’;
$_POST[‘sex’] = ‘M’;

$list = array(

$fp = fopen(‘test.csv’, ‘a’);

foreach ($list as $fields)
fputcsv($fp, $fields);