Grrr... I've got my program (almost) working correctly, but I don't know why when my code imports from CSV it adds to the table instead of replacing the old information ... I get lots of duplicate entries. Help?
Thanks in advance, and here's the code:
<?php
include "connect.php";
if(isset($_POST['submit']))
{
$filename=$_POST['filename'];
$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$import="REPLACE into info(alpha,beta,c,delta,alex) values('$data[0]','$data[1]','$data[2]',...
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
}
else
{
print "<form action='import.php' method='post'>";
print "Type file name to import:<br>";
print "<input type='text' name='filename' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>
Tags: