IstominV

html[todos.php]

Jul 24th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php session_start(); ?>
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <title>simple to-do list</title>
  6. </head>
  7. <body>
  8. <form action="form.php" method="POST">
  9. <h2>task name:</h2>
  10. <input name="task" />
  11. <br>
  12. <button>save</button>
  13. </form>
  14.  
  15. <?php if (count($_SESSION['tasks']) == 0): ?>
  16.  
  17. <br>you have no tasks
  18.  
  19. <?php else: ?>
  20.  
  21. <h3>you have: <?php echo count($_SESSION['tasks']); ?> tasks</h3>
  22. <h3>your tasks:</h3>
  23. <ul>
  24. <?php
  25.  
  26. if(isset($_GET['del'])) {
  27. $delete_key = $_GET['del'];
  28. if(isset($_SESSION['tasks'][$delete_key])) {
  29. unset($_SESSION['tasks'][$delete_key]);
  30. }
  31. } ?>
  32.  
  33. <ul>
  34. <?php foreach ($_SESSION['tasks'] as $key => $value) {
  35. echo "<li>{$value} <a href=\"{$_SERVER['PHP_SELF']}?del={$key}\">[Del]</a></li>";
  36. } ?>
  37. </ul>
  38.  
  39. </ul>
  40.  
  41. <br>
  42. <br>
  43.  
  44. <a href="clear.php">remove all my tasks</a>
  45.  
  46.  
  47. <?php endif; ?>
  48.  
  49. </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment