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.
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
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-Disposition: attachment; filename="' . $FileName . '"'