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
- if(isset($_GET['del'])) {
- $delete_key = $_GET['del'];
- if(isset($_SESSION['tasks'][$delete_key])) {
- unset($_SESSION['tasks'][$delete_key]);
- }
- } ?>
- <ul>
- <?php foreach ($_SESSION['tasks'] as $key => $value) {
- echo "<li>{$value} <a href=\"{$_SERVER['PHP_SELF']}?del={$key}\">[Del]</a></li>";
- } ?>
- </ul>
- </ul>
- <br>
- <br>
- <a href="clear.php">remove all my tasks</a>
- <?php endif; ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment