?
Solved

Exporting data from PHP form to Excel/CSV file.

Posted on 2010-08-13
4
Medium Priority
?
322 Views
Last Modified: 2013-12-13
Hello,

I would like to know how do export php form data (Online Registration Details) to Excel or csv file. For eg: it should be saved in the excel file automatically, each time any new user registers and fills up the php form. All the information of users would be in this excel file. As of now, we get an email with the new registrations. But apart from getting emails, all details should also be saved in this excel file automatically.
Please let me know some quick solution or code as its needed urgently for my project.

Thanks.
0
Comment
Question by:rutlandict
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 14

Accepted Solution

by:
Kalpan earned 1000 total points
ID: 33428444
0
 
LVL 5

Assisted Solution

by:doyledp
doyledp earned 1000 total points
ID: 33428468
Alternatively if using csv do the following

// open the log file and check if the it's opened successfully. The 'a' means append
if (!($fp = fopen('output.csv', 'a'))) {
   die('Cannot open log file');
}


//Create your string. Make sure to have new line at the end i.e. \n
$line = $user . "," . $email . "," ....... "\n";
// append to file
fwrite($fp, $line);

//close the file
fclose($fp)
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 33437085
You should change the design pattern for this application.  Instead of saving data in an EXCEL file, you should save the online registration details in a data base.  You can easily get information from the data base to create a CSV file (almost universally associated with Excel) and you can email CSV files with ease.

PHP has functions like fgetcsv() and fputcsv() that facilitate using the CSV files.  Most SQL data bases have export functions that can give you a CSV, too.

The advantages of using a data base instead of an Excel file are too numerous to mention, but please trust me - that is the way to go.  An experienced developer can get you up and running with something like this in less than a day.

best of luck with your project, ~Ray
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question