Good evening, I have a question.
I'm uploading a file and extracting its contents and inserting into my database, but I'm having a question about using the array as value
>My file consists of a sequence of numbers separated by 15 blocks divided by a | and a break of lines between every 15 blocks
Ex. of the reading file 02 | 01 | 020320171212 | 524419188 | 206 | 000011900173 | 03 | 700000 | 700000 | 644490 | 033438 | 2622221 | C | M | C | | 02 | 01 | 020320171427 | 524418372 | 206 | 000011915070 | 01 | 31900 | 31900 | 31102 | 250802 | 2623485 | C | M | D |
Ex. of my code upload.php
<?php
include 'conect.php';
///RECEBE PELO METODO POST
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$tmpName = $_FILES['userfile']['tmp_name'];
///ABRE O ARQUIVO
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
///SEPARA OS BLOCOS
$array=explode("|",$content);
for($i = 0; $i < count($array); $i++) {
$query = mysql_query("INSERT INTO dados (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) VALUES ( '".$array[$i]."' ");
/// Está dando o erro de Query was empty
mysql_query($query) or die(mysql_error());
}
if(mysql_affected_rows() != 0){
echo "<script type='text/javascript'>window.alert('$fileName Enviado!');</script>";
echo '<meta HTTP-EQUIV="Refresh" CONTENT="1; URL=lista.php">';
exit;
}
}
?>
I want to insert into the database the information contained in this file so I created a table with the columns in names of a, b, c ...
If anyone can help me, I'm very grateful!
Att; Danilo Braga