Welcome to Smarter QA, Questions, Answers Community
Welcome to Smarter QA, where you can ask questions and receive answers from other members of the community. Ask anything that you want. Guests Posting are allowed.
+2 votes
41 views

Save HTML  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 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 excel file and output. 

Kindly help me. 

asked in PHP by (1.1k points)

1 Answer

0 votes
 
Best answer

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 on one click after that you have to convert the database data into the excel formate.

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 on 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 )

answered by (800 points)
selected by
...