I think I'm close but the script below will not loop... therefore it only writes a single line to the database. Help!
--------------------
<?php
$databasehost = "localhost";
$databasename = "$db";
$databasetable = "$table";
$databaseusername ="$user";
$databasepassword = "$pass";
$fieldseparator = ",";
$lineseparator = "\n";
$csvfile = $_FILES['dataupload']['tmp_name'];
if (!file_exists($csvfile)){
echo "File not found. Make sure you specified the correct path.\n";
exit;
}
$file = fopen($csvfile,"r");
if (!$file){
echo "Error opening data file.\n";
exit;
}
$size = filesize($csvfile);
if(!$size){
echo "File is empty.\n";
exit;
}
$csvcontent = fread($file,$size);
fclose($file);
$con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
@mysql_select_db($databasename) or die(mysql_error());
$lines = 0;
$queries = "";
$linearray = array();
$lineexp = explode($lineseparator,$csvcontent);
foreach($lineexp as $line){
$lines++;
$line = trim($line," \t");
$line = str_replace("\r","",$line);
$line = str_replace("'","\'",$line);
$linearray = explode($fieldseparator,$line);
$linemysql = implode("','",$linearray);
$query = "INSERT INTO $databasetable VALUES('$linemysql')";
$upload = @mysql_query($query);
}
if ($upload){
header ("location:index.php?count=$lines");
exit();
}
else {
header ("location:index.php?error=1");
exit();
}
?>