Reputation: 139
I have the following code that adds data from my form to an excel spreadsheet. However, when a new user fills out the form it overwrites the data on the first row, how would I make sure that new form submissions populate a new row in this file "datacollection.xlsx"
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$title = $_POST['title'];
$company = $_POST['company'];
$fp=fopen(".datacollection.xlsx","w");
fputcsv($fp, array($name, $email, $title, $company), ';');
fclose($fp);
?>
Help is appreciated!
Upvotes: 1
Views: 2104
Reputation: 100205
use a+
instead of w
mode of fopen(), so that it places the file pointer at the end of the file. Like:
...
$fp=fopen(".datacollection.xlsx","a+"); //use a+ instead of w
fputcsv($fp, array($name, $email, $title, $company), ';');
...
Upvotes: 3