Task-list manager app in PHP doesn't show the list of tasks
<p>I am working on a task list manager for my class that I am in. I have to include sessions and I need to push each task into an array and be able to delete it from the array.</p>

<p>I think I am doing it correctly,but when I run the program, the task list shows up as empty. I think I may not be adding the tasks to the task-list array correctly, and I really would like a fresh set of eyes to take a look, because maybe you will see what I haven't.</p>

<h3>index.php</h3>

<pre><code>&lt;?php
if (isset($_POST['tasklist'])) {
$task_list = $_POST['tasklist'];
} else {
$task_list = array();
}

// put the array in a session variable
$_SESSION['tasks']=$task_list;
$_SESSION['errors']=$errors;

//start the session to last one year
$lifetime = 60 * 60 * 24 * 365;     // 1 year in seconds
ini_set('session.gc_maxlifetime', $lifetime);
//session_set_cookie_params($lifetime, '/');
session_start();

$errors = array();

switch( $_POST['action'] ) {
    case 'add':
    $new_task = $_POST['newtask'];
    if (empty($new_task)) {
        $_SESSION['errors'] = 'The new task cannot be empty.';
    } else {
        $_SESSION['tasks'] = $new_task;
    }
    break;
case 'delete':
    $task_index = $_POST['taskid'];
    unset($task_list[$task_index]);
    $_SESSION['tasks'] = array_values($_SESSION['tasks']);
    break;
}



include('task_list.php');
?&gt;
</code></pre>

<h3>task_list.php</h3>

<pre><code>   &lt;?php
   session_start(); // Access the current session.

?&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="page"&gt;
&lt;div id="header"&gt;
    &lt;h1&gt;Task List Manager&lt;/h1&gt;
&lt;/div&gt;
&lt;div id="main"&gt;

&lt;!-- part 1: the errors --&gt;
&lt;?php if (count($_SESSION['errors']) &gt; 0) : ?&gt;
&lt;h2&gt;Errors&lt;/h2&gt;
&lt;ul&gt;
    &lt;?php foreach($_SESSION['errors'] as $error) : ?&gt;
        &lt;li&gt;&lt;?php echo $error; ?&gt;&lt;/li&gt;
    &lt;?php endforeach; ?&gt;
&lt;/ul&gt;
&lt;?php endif; ?&gt;

&lt;!-- part 2: the tasks --&gt;
&lt;h2&gt;Tasks&lt;/h2&gt;
&lt;?php if (count($_SESSION['tasks']) == 0) : ?&gt;
    &lt;p&gt;There are no tasks in the task list.&lt;/p&gt;
&lt;?php else: ?&gt;
    &lt;ul&gt;
    &lt;?php foreach($_SESSION['tasks'] as $id =&gt; $task) : ?&gt;
        &lt;li&gt;&lt;?php echo $id + 1 . '. ' . $task; ?&gt;&lt;/li&gt;
    &lt;?php endforeach; ?&gt;
    &lt;/ul&gt;
&lt;?php endif; ?&gt;
&lt;br /&gt;

&lt;!-- part 3: the add form --&gt;
&lt;h2&gt;Add Task&lt;/h2&gt;
&lt;form action="." method="post" &gt;
    &lt;?php foreach($_SESSION['tasks'] as $task) :
      array_push($_SESSION['tasks'],$task);
     endforeach; ?&gt;
    &lt;!--&lt;input type="hidden" name="action" value="add"/&gt; --&gt;
    &lt;label&gt;Task:&lt;/label&gt;
    &lt;input type="text" name="&lt;?php $_SESSION['tasks'] ?&gt;" id="newtask" value="&lt;?php     echo $task; ?&gt;" /&gt; &lt;br /&gt;
    &lt;label&gt;&amp;nbsp;&lt;/label&gt;
    &lt;input type="submit" value="Add Task"/&gt;
&lt;/form&gt;
&lt;br /&gt;


&lt;!-- part 4: the delete form --&gt;
&lt;?php if (count($_SESSION['tasks']) &gt; 0) : ?&gt;
&lt;h2&gt;Delete Task&lt;/h2&gt;
&lt;form action="." method="post" &gt;
    &lt;?php foreach($_SESSION['tasks'] as $task) :
      $_SESSION['tasks']=array_diff($_SESSION['tasks'],$task);
     endforeach; ?&gt;
    &lt;!--&lt;input type="hidden" name="action" value="delete"/&gt; --&gt;
    &lt;label&gt;Task:&lt;/label&gt;
    &lt;select name="taskid"&gt;
        &lt;?php foreach($_SESSION['tasks'] as $id =&gt; $task) : ?&gt;
            &lt;option value="&lt;?php echo $id; ?&gt;"&gt;
                &lt;?php echo $task; ?&gt;
            &lt;/option&gt;
        &lt;?php endforeach; ?&gt;
    &lt;/select&gt;
    &lt;br /&gt;
    &lt;label&gt;&amp;nbsp;&lt;/label&gt;
    &lt;input type="submit" value="Delete Task"/&gt;
&lt;/form&gt;
&lt;?php endif; ?&gt;

&lt;/div&gt;&lt;!-- end main --&gt;
&lt;/div&gt;&lt;!-- end page --&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
