Good, I'm making a website, where I will get a txt file that the user will upload (always in msm format (process, name, number)). I am trying to use arrays to fetch the data and insert it into the database. I already managed to fetch but I can not get the data in the array. for example, I have in the txt file this line (12345, andre, 1) and I want the array to be array 1 = 12345, array 2 = andre and array 1, to cycle all the students into bd. >
I tried several codes and I did not get anywhere, this was the last one I tried; include ("includes \ ligacaobd.php"); $ file = ('students.txt'); $ separator=""; // What separates results in TXT files?
if(file_exists($arquivo)){
$fp=fopen($arquivo,'r');
while(!feof($fp)){
$line = trim(fgets($fp));
if (empty($line)) {
continue;
}
$lines = rtrim($line, ';'); //remover o ';' que tens no fim de cada linha
$array = explode($separador, $lines); //separar por $separador
$sql1 = "INSERT INTO aluno (numero, nome, processo) VALUES ('" . $array[0] . "', '" . @$array[1] . "', '" . @$array[2] . "')";
$resultado1 = mysqli_query($conn,$sql1);
if(!$resultado1){
print "Falha na linha: " . $line;
}
}
fclose($fp);
print "Terminado";
}
Can you help me?