Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Exporting data from PHP form to Excel/CSV file.

Posted on 2010-08-13
4
Medium Priority
?
332 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
3 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Suggested Courses
Course of the Month20 days, 23 hours left to enroll

810 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