Good afternoon, I am trying to create a page on my website is wordpress in which the user chooses a file and this file updates a table in the database.
I got code below, but when I click load data, nothing happens. The function is not being called.
<div style="width: 50%;margin: 20px auto; ">
<form action="" method="POST">
Selecione o arquivo desejado:
<select>
<option value="" selected="selected">-----</option>
<?php
foreach(glob('files/*') as
$filename){
$filename = basename($filename);
echo "<option value='" . $filename . "'>".$filename."</option>";
}
?>
</select>
<input type='submit' value='Carregar dados'>
</form>
</div>
<?php
if(isset($_POST)){
function insere() {
echo $filename;
echo "apagando dados da tabela...<br>";
$delete = $wpdb->query("TRUNCATE TABLE 'i_renda'");
$ler=file("files/".$filename);
foreach($ler as $linha) {
$dados=explode(';',$linha);
list($nome, $cpf, $nascimento, $valor, $ano_vigencia)=$dados;
$wpdb->query("INSERT INTO i_renda (nome, cpf, nascimento, valor, ano_vigencia) VALUES ('".utf8_encode($nome)."', '$cpf', '$nascimento', '$valor', '$ano_vigencia')" );
}
echo "Dados incluidos com sucesso!"; exit;
}
}
?>