How to save html form data to excel file using php ?

2
(183 Views)

×

Please Login or Register to process.

 form data to excel file using PHP:-

I am working on a PHP project. I want to generate a CSV  (excel ) file using HTML form. I am new to PHP development. I don't know how to save HTML form data to an excel file using PHP? I need your help to generate an Excel file from the HTML form.  

I elaborated hare that I will create an HTML form. The HTML form will contain the Name, Email, Address, Mobile no, etc. When someone click fills the form and clicks on the submit button it will produce an excel file and output. 

Kindly help me. 

asked 23 Oct 2018 in PHP by priyasharma4005(4.1K Points)

Share

1 Answer
answered 23 Oct 2018 by arnabisaha(2.1K Points) (edited)
0

Save HTML  form data to excel file using PHP:- 

Ok! You are looking for "Save HTML form data into to excel file using PHP".Think about it, Excel ( CSV ) format is very useful to store the data in one file. There are a lot of ways to save the HTML form data into the excel file.

You can create a database table and retrieve the all data in one click after that you have to convert the database data into excel format.

But your question is different. Your solution is very easy. You can get the excel (CSV ) format without creating the database.

Create an HTML form.     The HTML form will contain the fields like 

Name 

Address,

 Mobile no,

Email. 

Etc. 

You can add more fields in the HTML form. 

When someone fills the form and click on submit button the result will be an excel file.

The excel file will contain the all HTML form field data.  

 $Content = "Name,address,mobileno,email\n";

//set the data of the CSV

 $Content .= "$name,$address,$mobileno,$email\n";

 //set the file name and create CSV file

 $FileName = "Myfile-".date("d-m-y-h:i:s").".csv";

  header('Content-Type: application/csv'); 

  header('Content-Disposition: attachment; filename="' . $FileName . '"'

echo $Content;

 

FORM DATA INTO CSV(EXCEL FILE )


Comment

Related Questions :-

Your Answer

You can post your answer after login..