Solved

Exporting data from PHP form to Excel/CSV file.

Posted on 2010-08-13
4
305 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

910 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