0
I am studying PHP with a book I bought and the exercise is to create a task list. The browser is returning me the following error:
Notice: Undefined variable: lista_tarefas in C: Users Elton Desktop Cadastro root Listadetarefas template.php on line 26
Warning: Invalid argument supplied for foreach() in C: Users Elton Desktop Cadastre root Listadetarefas template.php on line 26 Tasks
The error snippet in template.php is this code:
<table>
<tr>
<th>Tarefas</th>
</tr>
<?php foreach($lista_tarefas as $tarefa) : ?>
<tr>
<td><?php echo $tarefa; ?></td>
</tr>
<?php endforeach; ?>
</table>
And the PHP code I’m using is this:
<?php
session_start();
if (array_key_exists('nome', $_GET)){
$_SESSION['lista_tarefas'][] = $_GET['nome'];
}
$lista_tarefas = [];
if (array_key_exists('lista_tarefas', $_SESSION)){
$lista_tarefas = $_SESSION['lista_tarefas'];
}
?>
Please help me understand where I’m going wrong. I couldn’t get to the error.
Adds to URL that you are using to access the file so that we can analyze it better, because your file is receiving parameters via GET.
– pauloimon
These two code snippets are in the same file or are separate files?
– pauloimon
http://localhost:8079/Listadetarefas/template.php? nome=d
– Elton Rodrigues
Are in separate files
– Elton Rodrigues