Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start(); ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>simple to-do list</title>
- </head>
- <body>
- <form action="form.php" method="POST">
- <h2>task name:</h2>
- <input name="task" />
- <br>
- <button>save</button>
- </form>
- <?php if (count($_SESSION['tasks']) == 0): ?>
- <br>you have no tasks
- <?php else: ?>
- <h3>you have: <?php echo count($_SESSION['tasks']); ?> tasks</h3>
- <h3>your tasks:</h3>
- <ul>
- <?php
- foreach ($_SESSION['tasks'] as $task) {
- print '<li>';
- print htmlspecialchars($task);
- print '<button>del</button>';
- print '</li>';
- }
- ?>
- </ul>
- <br>
- <br>
- <a href="clear.php">remove all my tasks</a>
- <?php endif; ?>
- <?php
- if(isset($_SESSION[$_GET['delete']])) unset($_SESSION[$_GET['delete']]);
- echo "<ul>";
- foreach ($_SESSION['tasks'] as $key => $value) {
- echo "<li>{$value} <a href=\"{$_SERVER['PHP_SELF']}?delete={$key}\">[Delete]</a></li>";
- }
- echo "</ul>";
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment