I have a code through which i want to import csv file into databse. But i am getting an error:
fopen() [function.fopen]: Filename cannot be empty and points on line 36(have marked in the code
Would appreciate if anyone could help me -
<?php
-
if ($_FILES["file"]["error"] > 0)
-
{
-
echo "Error: " . $_FILES["file"]["error"] . "<br>";
-
}
-
else
-
{
-
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
-
echo "Type: " . $_FILES["file"]["type"] . "<br>";
-
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br>";
-
//echo "Stored in: " . $_FILES["file"]["tmp_name"];
-
$a=$_FILES["file"]["tmp_name"];
-
//echo $a;
-
-
$connect = mysql_connect('example.com','employee','172');
-
if (!$connect) {
-
die('Could not connect to MySQL: ' . mysql_error());
-
}
-
//your database name
-
$cid =mysql_select_db('employeemgt',$connect);
-
-
// path where your CSV file is located
-
//define('CSV_PATH','C:/xampp/htdocs/');
-
//<!-- C:\xampp\htdocs -->
-
// Name of your CSV file
-
$file = $a;
-
-
if (($getfile = fopen($file, "r")) !== FALSE) { //line36
-
$data = fgetcsv($getfile, 1000, ",");
-
while (($data = fgetcsv($getfile, 1000, ",")) !== FALSE) {
-
//$num = count($data);
-
//echo $num;
-
//for ($c=0; $c < $num; $c++) {
-
$result = $data;
-
$str = implode(",", $result);
-
$slice = explode(",", $str);
-
-
$col1 = $slice[0];
-
$col2 = $slice[1];
-
$col3 = $slice[2];
-
$col4 = $slice[3];
-
$col5 = $slice[4];
-
$col6 = $slice[5];
-
$col7 = $slice[6];
-
$col8 = $slice[7];
-
$col9 = $slice[8];
-
$col10 = $slice[9];
-
$col11 = $slice[10];
-
$col12 = $slice[11];
-
$col13 = $slice[12];
-
$col14 = $slice[13];
-
$col15 = $slice[14];
-
$col16 = $slice[15];
-
$col17 = $slice[16];
-
$col18 = $slice[17];
-
$col19 = $slice[18];
-
$col20= $slice[19];
-
$col21= $slice[20];
-
$col22 = $slice[21];
-
$col23 = $slice[22];
-
$col24 = $slice[23];
-
$col25 = $slice[24];
-
$col26 = $slice[25];
-
$col27 = $slice[26];
-
$col28 = $slice[27];
-
$col29 = $slice[28];
-
$col30 = $slice[29];
-
$col31 = $slice[30];
-
$col32 = $slice[31];
-
-
-
$query = "INSERT INTO temp(id,firstname,lastname,displayname,nickname,email,email2,homephone,busnphone,fax,pager,mobphone,homestreet,homeaddress2,homecity,homestate,home,postalcode,homecountry,busadrs,busadrs2,buscity,busstate,buspostalcode,busicountry,jobtitle,deptt,orgnztn,notes,bday,webpage,webpage2,categories) VALUES('".$col1."','".$col2."','".$col3."','".$col4."','".$col5."','".$col6."','".$col7."','".$col8."','".$col9."','".$col10."','".$col11."','".$col12."','".$col13."','".$col4."','".$col15."','".$col16."','".$col17."','".$col18."','".$col9."','".$col20."','".$col21."','".$col22."','".$col23."','".$col24."','".$col25."','".$col26."','".$col27."','".$col28."','".$col29."','".$col30."','".$col31."','".$col32."')";
-
$s=mysql_query($query, $connect );
-
}
-
}
-
-
echo "File data successfully imported to database!!";
-
mysql_close($connect);
-
}
-
?>
-
hm, what do you think
Filename cannot be empty
means?
besides that, MySQL can import CSV directly.
1 1488
hm, what do you think
Filename cannot be empty
means?
besides that, MySQL can import CSV directly.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: matt |
last post by:
I don't have a database available, so i'm writing an Image Gallery with
a flat file database.
I have an Add Page:
Uploads Image file, and saves $filename and $caption to text file:
captions.txt...
|
by: matt |
last post by:
I am using a text file as a database, each field delimited by ||
I want to be able to print all lines to a page, then by selecting one
(with, say, a radio button) it will load into the form at the...
|
by: Steve Holden |
last post by:
I'm trying to load module code from a database, which stores for each
module its full name, code, load date and a Boolean indicating whether
it's a package or not.
The following simple program:...
|
by: Steve Holden |
last post by:
This is even stranger: it makes it if I import the module a second time:
import dbimp as dbimp
import sys
if __name__ == "__main__":
dbimp.install()
#k = sys.modules.keys()
#k.sort()
#for...
|
by: aa |
last post by:
How do I import Access database into MySQL?
|
by: Brian Huether |
last post by:
I saved my website databgase to my home computer. I am setting up a local
version of the site, and need to import the database. I have mysql and
everything set up. But when I try to run the sql...
|
by: Eric Caron |
last post by:
Hi
I try to import file in a dataset. How I can do this ?
|
by: jtippen |
last post by:
Can anyone point me in the right direction on how I can import a comma
delimited webpage off a website into a table in Access 2003?
If someone knows of an example of how to do this that would...
|
by: a.crowley |
last post by:
I have a large set of Word documents that I wish to catalogue in an
Access database. Each document has a set of file properties populated
(title, subject, author, keywords, comments ect), so I'd...
|
by: kaisersose1995 |
last post by:
Hi,
I've got an import procedure working, using a standard import
specification to import a .csv file into a temporary table.
The problem i'm having is that i have 4 different sets of borrower...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |