I'm trying to make a INSERT
using PHP to insert multiple records into the DB at once.
My code is only inserting the first row of the data. It even displays all the lines, but to insert, only the first one is sent to the DB.
include "conexao.php";
$arquivo = "txt/Coleta.TXT";
$objeto = fopen($arquivo, 'r');
while($dados = fgets($objeto))
{
$empresa = trim(substr($dados, 0, 4));
$funcionario = trim(substr($dados, 4, 6));
$local = trim(substr($dados, 10, 4));
$cracha = trim(substr($dados, 14, 8));
$data = trim(substr($dados, 22, 6));
$data_dia = substr($data, 0, 2);
$data_mes = substr($data, 2, 2);
$data_ano = substr($data, 4, 2);
$datames = "20$data_ano"."$data_mes"."$data_dia";
$hora = trim(substr($dados, 28, 4));
$sql_gravar = ("INSERT INTO cadhorames(codempre, codfunci, localfun, crachfun, datamfun, horafun) VALUE
('$empresa','$funcionario','$local','$cracha','$datames','$hora')");
mysql_query($sql_gravar);
?>
<form name="arqtxt" >
<table>
<tr>
<td><? echo $empresa ?> </td>
<td><? echo $funcionario ?> </td>
<td><? echo $local ?> </td>
<td><? echo $cracha ?> </td>
<td><? echo $datames ?> </td>
<td><? echo $hora ?> </td>
</tr>
</table>
<?
}
fclose($objeto);
</form>
Sample file:
00030000020001000000021808140730
00030000020001000000021808141100
00030000020001000000021808141300
00030000020001000000021808141750
00030000030001000001231708140900
00030000030001000001231708141200
00030000030001000001231708141300
00030000030001000001231708141800