import excel file to php myadmin through file uploading usin
Posted: Sat Jan 11, 2014 9:54 am
Hello,
Is it possible to upload excel file to my php myadmin. I know that all the field name of my phpmyadmin database table and my excel sheet table field should be same. But i am not finding the appropriate solution of this topic. The importing of my excel file code i am not finding out. And m confused in this.
Below is the code i tried out:
upload.php:
I had mistaken in my upload.php code. So, if some one could help me with the code here.
Any kind of help is appreciated.
Thanks in advance
Is it possible to upload excel file to my php myadmin. I know that all the field name of my phpmyadmin database table and my excel sheet table field should be same. But i am not finding the appropriate solution of this topic. The importing of my excel file code i am not finding out. And m confused in this.
Below is the code i tried out:
Code: Select all
<form action="upload.php">
<input type="file" name="txtFile" id="eskal" /></br>
<input type="submit" name="Import" value="Update Database" /> </b>
Code: Select all
<?php
if(isset($_POST["Import"]))
{
$host="localhost"; // Host name.
$db_user="root";
$db_password="";
$db='test'; // Database name.
$conn=mysql_connect($host,$db_user,$db_password) or die (mysql_error());
mysql_select_db($db) or die (mysql_error());
echo $filename=$_FILES["file"]["tmp_name"];
//echo $ext=substr($filename,strrpos($filename,"."),(strlen($filename)-strrpos($filename,".")));
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
print_r($emapData);
$sql = "INSERT into import(name,address,email,password) values('$emapData[0]','$emapData[1]')";
mysql_query($sql);
}
fclose($file);
echo "CSV File has been successfully Imported";
}
else
echo "Invalid File:Please Upload CSV File";
}
?>
Any kind of help is appreciated.
Thanks in advance