0
good, I am making a website, where you will find a txt file that the user will upload (always in msm format(process, name, number)). I’m trying to use arrays to search the data and enter it in the database. I can already search but I can’t put 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 make a cycle to insert all students in the bd.
I’ve tried a lot of codes and I’ve gotten nowhere, this is the last one I’ve tried; include("includes ligacaobd.php"); $file=('students.txt'); $separator = "; // What separates the results in the 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 help me?