By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,615 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,615 IT Pros & Developers. It's quick & easy.

how to upload an excell data into mysql with php

P: 1
there is my script'anyway i am new to php and any help is apprecited thanks.

<?php
// Connect to database
mysql_connect("localhost", "root", "") or die(mysql_error());

mysql_select_db("Massive") or die(mysql_error());

$fp = fopen("emp.txt", "r") // Open the file for reading
while ($line = fgets($fp)) { // Loop through each line
list ($id, $first, $middle, $last) = split("\t", $line, 4); // Split the line by the tab delimiter and store it in our list

$sql = "insert into employees (id, firstname, middlename, lastname) values ('$id', '$first', '$middle', '$last')"; // Generate our sql string

mysql_query($sql) or die ( mysql_error() ); // Execute the sql

}
?>
Oct 19 '11 #1
Share this Question
Share on Google+
1 Reply


100+
P: 1,059
You can use PHPExcel to extract data or may be you also can do this.

First export the excel file to csv and then make program to read it in php
Oct 19 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.