0
I need some help, I created an import code for XML
to the MYSQL
via PHP
.
Follows code:
<?php
if (!isset($seg)) {
exit;
}
//$dados = $_FILES['arquivo'];
if (!empty($_FILES['arquivo']['tmp_name'])) {
$DOMDocument = new DOMDocument( '1.0', 'UTF-8' );
$DOMDocument->preserveWhiteSpace = false;
$DOMDocument->load($_FILES['arquivo']['tmp_name']);
$products = $DOMDocument->getElementsByTagName("Row");
foreach($products as $product){
$cpf = $product->getElementsByTagName("Data")->item(0)->nodeValue;
$nome_cliente = $product->getElementsByTagName("Data")->item(1)->nodeValue;
$telefone = $product->getElementsByTagName("Data")->item(2)->nodeValue;
$dataemissao = $product->getElementsByTagName("Data")->item(3)->nodeValue;
$vencimento = $product->getElementsByTagName("Data")->item(4)->nodeValue;
$funcionario = $product->getElementsByTagName("Data")->item(5)->nodeValue;
$adesao_mensalidade = trim($product->getElementsByTagName("Data")->item(6)->nodeValue);
$forma_envio = $product->getElementsByTagName("Data")->item(7)->nodeValue;
$data_liquidacao = $product->getElementsByTagName("Data")->item(8)->nodeValue;
$result_import = "INSERT INTO adms_liquida_boletos_plano (cpf, nome_cliente, telefone, emissao, vencimento, vendedor, adesao_mensalidade, forma_envio, data_liquidacao, inserido) VALUES ('$cpf','$nome_cliente','$telefone','$dataemissao','$vencimento','$funcionario','$adesao_mensalidade', '$forma_envio','$data_liquidacao', NOW())";
$resultado_import = mysqli_query($conn, $result_import);
} if (mysqli_insert_id($conn)) {
$_SESSION['msg'] = "<div class='alert alert-success'>Notas importadas com sucesso! <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button></div>";
$url_destino = pg . '/importar/import_liquid_plano';
header("Location: $url_destino");
}else{
$_SESSION['msg'] = "<div class='alert alert-danger'>ERRO: Notas não foram importadas! <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button></div>";
$url_destino = pg . '/importar/import_liquid_plano';
header("Location: $url_destino");
}
}
However, there is an error that imports blank cells, I would like to know how to make sure that this problem does not happen.
If you can send an example xml, it might be easier to find other ways to solve, I’ve already handled XML but without using Domdocument.
– Vinicius De Jesus