mailing form data as CSV

I am in need of some help. I have been tasked with collection of data and putting it into a spreadsheet. I have tried every google search I can think of and am not finding what I need.

Here’s what I am trying to do. I am running a drawing on facebook. I need to have the form data that entrants fill out put in a CSV so I can have numbers assigned to all entrants and allow use of a RNG to pick a winner. I’m not proficient in php, but know how to us forms. What kind of code would allow me to put all the information in one CSV file as it is collected over a set period of time?

Thanks in advance for any help.

Here is a quick example of how you can save mailing form data to csv file:

HTML form:

[code]

Name:
Email:
[/code]

PHP script save.php
[php]<?php
if($_POST[‘submit’]){

// here you'll need validate user input
if($_POST['name']=='' or $_POST['email']=='') die('Please enter your name and email!');

// append data to an existing csv file or create new file
$fp=fopen('data/records.csv','a');
if($fp){
  $line='"'.date("m/d/Y h:ia").'","'.str_replace('"','""',$_POST['name']).'","'.str_replace('"','""',$_POST['email']).'"';
  fputs($fp,$line."\r\n");
}
fclose($fp);    

}
?>[/php]

Few notes:

  • make sure so set writing permissions to the directory data/
  • disallow access to this directory from web, for example with .htaccess
Sponsor our Newsletter | Privacy Policy | Terms of Service