Solved

Exporting data from PHP form to Excel/CSV file.

Posted on 2010-08-13
4
303 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
4 Comments
 
LVL 14

Accepted Solution

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

Assisted Solution

by:doyledp
doyledp earned 250 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 108

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

758 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now