1
Good evening, in my code when I send the CSV file It records only the last line of the file, when I use TRUNCATE TABLE. Without the truncate saves all lines, but the goal is to update the data by deleting them and inserting new ones. Can anyone help me? Follow code:
if(isset($_FILES["file"])) { if(isset($_FILES["file"])) { $filename = $_FILES["file"]["name"]; $arquivotipo = $_FILES["file"]["type"]; $arquivotmp_name = $_FILES["file"]["tmp_name"]; $archived = $_FILES["file"]["size"]; }
}
$arquivo = fopen($arquivotmp_name, "r");
while(($dados= fgetcsv($arquivo,1000, ";")) !== FALSE)
    {
        $chapa = $dados[0];
        $departamento = $dados[1];
        $setor = $dados[2];
        
        
        $query1 = "TRUNCATE TABLE tabela"; //apaga todos os dados da tabela
        
        $queryexec1 = mysqli_query($conn, $query1);
        
        $query2 = "INSERT INTO tabela (chapa, departamento, setor) VALUES ('$chapa', '$departamento', '$setor')";
        
       $queryexec2 =  mysqli_query($conn, $query2);
        
    }
    
    if($queryexec1 && $queryexec2 !== FALSE)
        {
            echo "Dados enviados com sucesso!";
        }
    else
        {
            echo "Erro";
        }
						
You shouldn’t give TRUNCATE out of of the loop?
– anonimo
Dude worked out! Thanks, I’m new to the programming so some things go unnoticed!! Thanks a lot!!
– Almino