Validate duplicate records when uploading CSV

0

What I need is to be able to upload a .CSV file, and if in the bd there is already a record with a duplicate RETURN and PROCESS number, I skipped a script saying that there is already a record with that number of the form and process . So far the code that I have is this:

extract($_POST);
if ($action == "upload") {
$archivo = $_FILES['file']['tmp_name'];
$row = 1 - 1; 
$fp = fopen ($archivo,"r");

$PLANILLA = $_POST['PLANILLA'];
$PROCESO = $_POST['PROCESO'];

mysql_select_db($database_conexion, $conexion);
$query_valida_planilla = "SELECT PLANILLA, PROCESO FROM acta_entrega_huawei 
WHERE PLANILLA = '$PLANILLA' AND PROCESO = '$PROCESO'";
$valida_planilla = mysql_query($query_valida_planilla, $conexion) or 
die(mysql_error());
$row_valida_planilla = mysql_fetch_assoc($valida_planilla);
if(mysql_num_rows($valida_planilla)>0){
echo '<script>alert("Ya existe un numero de planilla y proceso duplicado en 
la base de datos, Por favor revise el archivo");</script>';

}else{
while ($data = fgetcsv ($fp, 1000, ";")){ 
  $num = count ($data); 
  print ""; 
  $row++; 

  $insertar="INSERT INTO acta_entrega_huawei (IDE, PLANILLA, N_PEDIDO, 
  PROCESO, FECHA_E_FAC, HORA, FECHA_E_CON, FECHA_OPE, OBSERVACIONES) VALUES 
  ('$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]', 
  '$data[6]', '$data[7]', '$data[8]')"; 
  mysql_query($insertar);
  }   
  fclose ($fp); 

  echo "<td><center><font face=\"arial\" color=\"green\"><b>Registros 
  Insertados ".$row."</b></font></center></td>";
     }
  }

When I upload the file it tells me that N records have been inserted, even if they are duplicates, but nothing is inserted in the bd, but it does not show me the duplicate records alert either. I have already verified several post but I can not find the solution. I hope you can help me and thank you in advance.

    
asked by Anderviver 10.07.2017 в 16:24
source

0 answers