Jump to content

gregaspen

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

gregaspen's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Pardon my think out loud process here but after inserting the echo, I shouldn't see an end of line since the foreach loop is only inserting a line at a time. So I'm back where I started. This should work but doesn't. Okay, class. Any hands?
  2. if I place echo ($linemysql); exit(); after implode. I only get the first line of data, properly formatted albeit. I should think I would get the entire database with the echo command. Am I on dope? OH WAIT! I am on dope. I should get rid of the exit and then comment out both the $query and $upload lines. Yip, now it shows the entire database... properly formatted, except for the end of line. Maybe that is my problem. But not sure how to fix it. anyone, anyone?
  3. 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(); } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.