I'm making a To do app for school with PHP. The problem i'm facing: I have 3 documents: index.php, application.php and CSS
My problem: every time I add a new task, my array is empty again and will only show the latest added item.
I think the problem is that "application.php" loads again every time I add a task. But I'm not sure how to fix that.
Index.php:
<form action="/Periodeopdracht/index.php" method="POST">
<div class="headerToDo">
<input class="addText title" type="text" value="Click to add a to do" name="nextToDo">
<input class="clickablePlus" type="submit" value="+" name="submit">
</div>
</form>
<?php if(!$empty): ?>
<?php foreach ($newToDo as $toDo): ?>
<div class="toDo">
<div class="textToDo"><?= $toDo ?></div>
</div>
<?php endforeach ?>
<?php endif ?>
Application.php:
<?php
$GLOBALS['empty'] = true;
$GLOBALS['newToDo'] = array();
if(isset($_POST["submit"]))
{
$empty = false;
array_unshift($newToDo, $_POST["nextToDo"]);
}
var_dump($newToDo);
?>