3
I have a file txt
that I am extracting information and in it the information is repeated 6 times, which inserts me in the database the same record also 6 times.
Setei UNIQUE
for a unique number to each record in the mysql database but when trying to run sql that inserts the data, gives a Entrada '120000001016' duplicada para a chave 'SQ_CANDIDATO'
and the insertion process is completed.
How could I solve this problem by entering only once each record in the bank without having to treat the txt
?
foreach ($itens as $item) {
$dados = explode(';', $item);
mysql_query("INSERT INTO VOT_CAND_MUN_ZONA VALUES (
'',
'".utf8_decode(trim($dados[0], '"'))."',
'".utf8_decode(trim($dados[1], '"'))."',
'".utf8_decode(trim($dados[2], '"'))."',
'".utf8_decode(trim($dados[3], '"'))."',
'".utf8_decode(trim($dados[4], '"'))."',
'".utf8_decode(trim($dados[5], '"'))."',
'".utf8_decode(trim($dados[6], '"'))."',
'".utf8_decode(trim($dados[7], '"'))."',
'".utf8_decode(trim($dados[8], '"'))."',
'".utf8_decode(trim($dados[9], '"'))."',
'".utf8_decode(trim($dados[10], '"'))."',
'".utf8_decode(trim($dados[11], '"'))."',
'".utf8_decode(trim($dados[12], '"'))."', <---- UNIQUE
'".utf8_decode(trim($dados[13], '"'))."',
'".utf8_decode(trim($dados[14], '"'))."',
'".utf8_decode(trim($dados[15], '"'))."',
'".utf8_decode(trim($dados[16], '"'))."',
'".utf8_decode(trim($dados[17], '"'))."',
'".utf8_decode(trim($dados[18], '"'))."',
'".utf8_decode(trim($dados[19], '"'))."',
'".utf8_decode(trim($dados[20], '"'))."',
'".utf8_decode(trim($dados[21], '"'))."',
'".utf8_decode(trim($dados[22], '"'))."',
'".utf8_decode(trim($dados[23], '"'))."',
'".utf8_decode(trim($dados[24], '"'))."',
'".utf8_decode(trim($dados[25], '"'))."',
'".utf8_decode(trim($dados[26], '"'))."',
'".utf8_decode(trim($dados[27], '"'))."',
'".utf8_decode(trim($dados[28], '"'))."'
)") or die (mysql_error());
It is an Insert with several values then?
– rray
Is inside a foreach
– Marcos Vinicius
Remove the
die
so it passes to the next line of the array and makes the next Insert.– rray
Perfect @rray put Unique but forgot to remove the die.
– Marcos Vinicius