I am using the followng code, to import csv into mysql.
if($_POST['sform'] == "1")
{
$fname = $_FILES['upload']['name'];
$chk_ext = explode(".",$fname);
if(strtolower($chk_ext[1]) == "csv")
{
$filename = $_FILES['upload']['tmp_name'];
$row = 1;
if (($handle = fopen($filename, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$row++;
$data_entries[] = $data ;
}
fclose($handle);
}
foreach($data_entries as $line)
{
$sql = "INSERT into testposts(ID,UID,title,tags,desc) values('','$data[0]','$data[1]','$data[2]','$data[3]')";
$conn->execute($sql);
$conn->execute($line);
}
$msg = "Successfully Imported";
}
else
{
$error = "Invalid File";
}
}
When I try to update then all values gets updated as 0
my csv file as follow (example)
1,title,tags,send2
Am not including ID value as it is auto incremented