Boa tarde !
Sou novo em PHP e estou lendo o livro acima e quando abro a página do template.php aparece o erro abaixo:
Notice: Undefined variable: lista_tarefas in C:\xampp\htdocs\OrganizarArquivos\template.php on line 47
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\OrganizarArquivos\template.php on line 47
Código template.php
identar texto pre-formatado em 4 espaços
<head>
<meta charset="utf-8" />
<title>Gerenciador de Tarefas</title>
<link rel="stylesheet" href="tarefas.css" type="text/css"/>
</head>
<body>
<h1>Gerenciador de tarefas</h1>
<form>Texto pré-formatado
<fieldset>
<legend>Nova tarefa</legend>
<label>
Tarefa:
<input type="text" name="nome"/>
</label>
<label>
Descrição:
<textarea name="descricao"></textarea>
</label>
<label>
prazo (Opcional):
<input type="date" name="prazo" />
</label>
</fieldset>
<fieldset>
<legend>Prioridade:</legend>
<label>
<input type="radio" name="prioridade" value="baixa" checked />Baixa
<input type="radio" name="prioridade" value="media" />Média
<input type="radio" name="prioridade" value="alta" />Alta
</label>
</fieldset>
<label>
Tarefa concluída:
<input type="checkbox" name="concluida" value="sim"/>
</label>
<input type="submit" value="Cadastrar" />
</form>
<table>
<tr>
<th>Tarefas</th>
<th>Descrição</th>
<th>Prazo</th>
<th>Prioridade</th>
<th>Concluída</th>
</tr>
<?php foreach ($lista_tarefas as $tarefa) : ?>
<tr>
<td><?php echo $tarefa['nome']; ?></td>
<td><?php echo $tarefa['descricao']; ?></td>
<td><?php echo $tarefa['prazo']; ?></td>
<td><?php echo $tarefa['prioridade']; ?></td>
<td><?php echo $tarefa['concluida']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
identar texto pre-formatado em 4 espaços
tarefas.php
<?php
session_start();
if (array_key_exists('nome', $_GET) && $_GET['nome'] != ''){
$tarefa = [] ;
$tarefa['nome'] = $_GET['nome'] ;
if (array_key_exists('descricao', $_GET)){
$tarefa['descricao'] = $_GET['descricao'] ;
}else{
$tarefa['descricao'] ='';
}
if (array_key_exists('prazo', $_GET)){
$tarefa['prazo'] = $_GET['descricao'] ;
}else{
$tarefa['prazo'] = '';
}
$tarefa['prioridade'] = $_GET['prioridade'] ;
if (array_key_exists('concluida', $_GET){
$tarefa['concluida'] = $_GET['concluida'] ;
}else{
$tarefa['concluida'] = '' ;
}
$_SESSION['lista_tarefas'][] = $tarefa ;
}
if(array_key_exists('lista_tarefas', $_SESSION)){
$lista_tarefas = $_SESSION['lista_tarefas'] ;
}
include "template.php";
?>`
Texto pré-formatado`