0% found this document useful (0 votes)
23 views

Note: Dont Forget To Save Excel File in .Cvs Format Before Executing This Code

This document provides code to import data from a CSV file into a MySQL database table. It uses PHP to check if the file uploaded is a CSV, then opens the file and loops through each row, executing an INSERT SQL statement to add the data to the user table. It outputs a success or invalid file message. Notes to save the Excel file as CSV first are also provided.

Uploaded by

api-126697740
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Note: Dont Forget To Save Excel File in .Cvs Format Before Executing This Code

This document provides code to import data from a CSV file into a MySQL database table. It uses PHP to check if the file uploaded is a CSV, then opens the file and loops through each row, executing an INSERT SQL statement to add the data to the user table. It outputs a success or invalid file message. Notes to save the Excel file as CSV first are also provided.

Uploaded by

api-126697740
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

if(isset($_POST<'SUBMIT'>)) { $fname = $_FILES<'sel_file'><'name'>; $chk_ext = explode(".

",$fname); if(strtolower($chk_ext<1>) == "csv") { $filename = $_FILES<'sel_file'><'tmp_name'>; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $sql = "INSERT into user(name,email,phone) values('$data<0>','$data<1>',' $data<2>'"; mysql_query($sql) or die(mysql_error()); } fclose($handle); echo "Successfully Imported"; } else { echo "Invalid File"; } } <form action='<?php echo $_SERVER<"PHP_SELF">;?>' method='post'> Import File : <input type='text' name='sel_file' size='20'> <input type='submit' name='submit' value='submit'> </form>

Note : Dont forget to save excel file in .cvs format before executing this code.

How to import the CSV/Excel file in to MYSQL database via using fgetcsv() function

By Mahesh

You might also like