Estoy tratando de insertar registros a mi base de datos desde un archivo txt, pero a la hora de insertar me marca el siguiente error:
Invalid Insert Query Column count doesn't match value count at row 1
Cual sera el problema?
Este es el codigo de programa y una muestra de los registros en la base de datos de txt.
Saludos y gracias por su pronta respuesta.
Código PHP:
<?
require('proveedo_connection.php');
$sql = "";
$sql_ext = "";
$sql .= " Select";
$sql .= " id,";
$sql .= " cve_prov,";
$sql .= " nom_prov,";
$sql .= " cod_prod,";
$sql .= " desc_prod,";
$sql .= " uni_med,";
$sql .= " fec_plan,";
$sql .= " cant01,";
$sql .= " cant02,";
$sql .= " cant03,";
$sql .= " cant04,";
$sql .= " cant05,";
$sql .= " cant06,";
$sql .= " cant07,";
$sql .= " cant08,";
$sql .= " cant09,";
$sql .= " cant10,";
$sql .= " cant11,";
$sql .= " cant12,";
$sql .= " cant13,";
$sql .= " cant14,";
$sql .= " cant15,";
$sql .= " cant16,";
$sql .= " cant17,";
$sql .= " cant18,";
$sql .= " cant19,";
$sql .= " cant20,";
$sql .= " cant21,";
$sql .= " cant22,";
$sql .= " cant23,";
$sql .= " cant24,";
$sql .= " total";
$sql .= " From";
$sql .= " proveedor";
$result = mysql_query($sql) or die("Query Invalido");
$avts = "plansai.txt";
$vts = array();
$vts = file($avts);
$nrg = $lst_id;
$nln = count ($vts);
echo ("Numero de Lineas in archivo : ".$nln."<br>");
for($i=0 ;$i<$nln ; $i++){
echo ("Linea : ".$vts[$i]."<br>");
$tar = explode(",",$vts[$i]);
$sqlin = "Insert into proveedor(id,cve_prov,nom_prov,cod_prod,desc_prod,uni_med,fec_plan,cant01,cant02,cant03,cant04,cant05,cant06,cant07,cant08,cant09,cant10,cant11,cant12,cant13,cant14,cant15,cant16,cant17,cant18,cant19,cant20,cant21,cant22,cant23,cant24,total) values ('',".$tar[1].",".$tar[2].",".$tar[3].",".$tar[4].",".$tar[5].",".$tar[6].",".$tar[7].",".$tar[8].",".$tar[9].",".$tar[10].",".$tar[11].",".$tar[12].",".$tar[13].",".$tar[14].",".$tar[15].",".$tar[16].",".$tar[17].",".$tar[18].",".$tar[19].",".$tar[20].",".$tar[21].",".$tar[22].",".$tar[23].",".$tar[24].",".$tar[25].",".$tar[26].",".$tar[27].",".$tar[28].",".$tar[29].",".$tar[30].",".$tar[31].")";
$result2 = mysql_query($sqlin) or die("Invalid Insert Query :-( ". mysql_error());
echo $sqlin."<br>";
}
?>
Código:
0,10223,"METALSA, S.A. DE C.V.","1059631R","REF-PACKING","PZ","2005-02-26",823.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,18.0000,122.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,146.0000,0.0000,0.0000,0.0000,0.0000,0.0000,10.0000,66.0000,0.0000,1185.0000 0,12499,"REFRISA, S.A. DE C.V.","1069603","FRONT DECK","PZ","2005-02-26",0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,2.0000,0.0000,2.0000