Hi, I have been trying to import the data from a CSV file (10,000 rows) into a database using SQL and PHP
<body>
<div id="container">
<div id="form">
<?php
$user="root";
$database="test";
mysql_connect("localhost",$user);
@mysql_select_db($database) or die( "Unable to select database");
//Upload File
if (isset($_POST['submit'])) {
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
}
$query = <<<eof
LOAD DATA INFILE '$filename' <<<<<<<<<<ERROR HERE
INTO TABLE importing
FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(text,number)
IGNORE 1 LINES
eof;
mysql_query($query);
print "Import done";
//view upload form
}else {
print "Upload new csv by browsing to file and clicking on Upload<br />\n";
print "<form enctype='multipart/form-data' action='upload.php' method='post'>";
print "File name to import:<br />\n";
print "<input size='50' type='file' name='filename'><br />\n";
print "<input type='submit' name='submit' value='Upload'></form>";
}
?>
</div>
</div>
</body>
</html>
the only error being returned is "Notice: Undefined variable: filename" and I can't see how to fix it no matter how much I look...
any help would be appreciated, I think i have been staring at code too long today lol