I have this code here please, which permits me to import data from a csv file into a database, now what this does is truncating the table before then inserting, I’ve tried to remove the truncate table before but then it wouldn’t pass the data. I mean how can I modify this code here? I need it just to insert the data, without emptying the current table!
Thanks..
$deleterecords = "TRUNCATE TABLE imovo"; //empty the table of its current records
mysql_query($deleterecords);
//Upload File
if (isset($_POST['submit'])) {
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
echo "<h2>Displaying contents:</h2>";
readfile($_FILES['filename']['tmp_name']);
}
//Import uploaded file to Database
$handle = fopen($_FILES['filename']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$import="INSERT into imovo(date,time,location,rbpos_id,mobile_number) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
//view upload form
}else {
}
“i’ve tried to remove the truncate table before but then it wouldn’t pass the data.”
Maybe because you have unique index and try insert duplicate record.