EDIT: I know that I have correctly installed PHP and the localhost server is running properly through MAMP.
I'm trying to create a todo list that saves the input to a txt file using PHP and then displays it. However, I can't get it to work. When I try to add a "todo item," it just disappears.
This first code snippet is where the todo item is added (the index.html file):
<div id="container">
<h1>To-do List<i class="fa fa-plus" aria-hidden="true"></i></h1>
<form action="index.php" method="post">
<input name="addtodo" type="text" placeholder="Add New To-Do">
</form>
<ul>
<li><span><i class="fa fa-trash"></i></span> Go to Potions Class</li>
</ul>
</div>
This is the index.php file where the todo item should ideally be added to the text file and displayed. It is not doing either.
<?php
//define variables
$addtodo = $_POST["addtodo"];
$DOCUMENT_ROOT = $_SERVER["DOCUMENT_ROOT"];
$filename = $DOCUMENT_ROOT.'todo.txt';
//write
$fp = fopen($filename, 'a');
$outputLine = $addtodo;
fwrite($fp, $outputLine);
fclose($fp);
?>
<div id="container">
<h1>To-do List<i class="fa fa-plus" aria-hidden="true"></i></h1>
<ul>
<li><span><i class="fa fa-trash"></i></span> Go to Potions Class</li>
</ul>
<?php
$display = "";
//read
$fp = fopen($filename, 'r');
while (true) {
$line = fgets($fp);
if (feof($fp)) {
break;
}
$display .= '<li><span><i class="fa fa-trash"></i></span>'.$line.'</li>';
}
fclose($fp);
echo $display;
?>
</div>
</body>