The following code I got to insert a tab-delimited text file to mysql.
But, I'm stuck on one part. I can INSERT, but I can't UPDATE. This script simply inserts anything in the text file, but if I accidentally click the refresh button 2x, then I've inserted the data 2x.
The first column in the text file is the unique id for what I'm uploading, which is just 3 columns: id, name, email
Here's what I've hammered out:
<?
require('db_conn.php');
$fcontents = file ('files/textfile.txt');
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode("\t", $line);
$sql = "insert into TABLE_NAME values ('". implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error()) { echo mysql_error() ."<br>\n"; }
}
?>
I'd like to try updating the records if I hit submit twice. This would be handy if I decided to change the email record for one of the records.
thanks a ton!