top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I insert the content of excel file into MySQL Table?

+5 votes
421 views

How can I insert the content of excel file into MySQL Table, any pointer?

posted Jun 28, 2016 by Salil Agrawal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+3 votes
 
Best answer

Hi ,follow these steps to insert your excel data into mysql table:
1. your excel file save it as YourFileName.csv(Common Delimited) format.Example: suppose your file contains slno,name and roll no of students then after saving it csv you will see it as

SLno,Name,RollNo
1,Shivam Pandey,100
2,Rohit Pandey,200

2.MySQL Table :

CREATE TABLE studentTable (
        SLno INT NOT NULL AUTO_INCREMENT,
        Name VARCHAR(255) NOT NULL,
        RollNo INT NOT NULL,
        PRIMARY KEY (RollNo)
    );  

3.Use this script to insert data( LOAD DATA INFILE ) :

LOAD DATA INFILE 'c:/users/queryhome/documents/studentDetails.csv' 
INTO TABLE studentTable 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

first line that contains the column headings, which should not be imported into the table.

answer Jun 28, 2016 by Shivam Kumar Pandey
Similar Questions
0 votes
for($i=0;$i<=feof($getdata);$i++)
{
if (filter_var($data[$i][1], FILTER_VALIDATE_EMAIL)){
echo $data[$i][1];
$email=$data[$i][1];
$conn = mysqli_connect($dbhost,$dbuser,$dbpass, $dbname);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
$sql ="INSERT INTO promo_user (uid,name,email) VALUES (,'', '$email')";
mysqli_query($sql,$conn);
mysqli_close($conn);

I am using the above code but there is something wrong with it,whenever i run the code the echo is working fine but the content does go into sql table

Please help

0 votes

How can I insert data into one table from two other tables where i have three tables namely users, role and userrole.
Now I want to insert the data into userrole table from users table and role table with a single statement.

+2 votes

How I 'll check how many rows inserted into every second on an average in a table of MySQL database?

...