Reputation:
I was wondering if it's possible to save the contents of a html form into csv format?
I was hoping to use it as an alternative to using a database.
Upvotes: 0
Views: 797
Reputation: 96258
store $_POST with fputcsv
see: http://php.net/manual/en/function.fputcsv.php
Upvotes: 0
Reputation: 15837
Of course. Take your fields and just put them into a file:
$data = '"'.addslashes($first).'","'.addslashes($second).'"'."\n";
file_put_contents('form.csv', $data, FILE_APPEND);
Upvotes: 0
Reputation: 218808
PHP has some built-in functionality to help with this.
as an alternative to using a database
Keep in mind that this isn't a drop-in replacement for an actual database engine. A few things to consider:
Upvotes: 2
Reputation: 3871
Sure
Matter of fact it is very easy and could be achieved with one line (Although I would not reccomend during this in production always validate input and you would also need to append to the file)
file_put_contents("mycsvfile.csv",implode(",", $_POST))
Upvotes: 0