1
I’m creating a program that stores a person’s tasks in an array, and shows them these tasks. But I’m having trouble showing the tasks. I can’t show the old tasks. Only the last task typed is shown.
Code:
<?php session_start(); ?>
<html>
<head>
<title>Gerenciador de Tarefas</title>
</head>
<body>
<h1>Gerenciador de Tarefas</h1>
</br>
<form>
<fieldset>
<legend>Nova Tarefa</legend>
<label>
Tarefa:
<input type="text" name="nome"/>
</label>
<input type="submit" value="Cadastrar"/>
</fieldset>
</form>
<?php
if (isset($_GET['nome'])) {
$_SESSION['lista_tarefas'] = $_GET['nome'];
}
$lista_tarefas = array();
if (isset($_SESSION['lista_tarefas'])) {
$lista_tarefas = $_SESSION['lista_tarefas'];
}
?>
<table>
<tr>
<th>Tarefas</th>
</tr>
<?php foreach($lista_tarefas as $tarefa) : ?>
<tr>
<td><?php echo $tarefa ?> </td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
Grateful for the attention!