I\'m wanting to store basic data from a single form box and I\'ve created this php code base, but it doesn\'t seem to be working. Can someone take a glance and see if anything
This part will not behave like you expect, the variables are not evaluated when inside single quotes:
$cvsData ='"$name","$date"'.PHP_EOL;
You will need to use double quotes:
$cvsData ="\"$name\",\"$date\"".PHP_EOL;
Use the nicer way in php : fputcsv
Otherwise you need to do lot of error handling to achieve in your case.
$list = array (
array('First Name', 'Last Name', 'Age'),
array('Angelina ', 'Jolie', '37'),
array('Tom', 'Cruise', '50')
);
$fp = fopen('file.csv', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
You should look into fputcsv. This will add CSV to you file and take care of fields and line ends.
fputcsv($fp,array(array($name,$date)));
You can also specify delimiters and such if you want.