IstominV

Untitled

Jul 24th, 2014
153
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. foreach ($_SESSION['tasks'] as $task) {
  26. print '<li>';
  27. print htmlspecialchars($task);
  28. print '<button>del</button>';
  29. print '</li>';
  30. }
  31. ?>
  32. </ul>
  33.  
  34. <br>
  35. <br>
  36.  
  37. <a href="clear.php">remove all my tasks</a>
  38.  
  39.  
  40. <?php endif; ?>
  41.  
  42. <?php
  43.  
  44. if(isset($_SESSION[$_GET['delete']])) unset($_SESSION[$_GET['delete']]);
  45.  
  46. echo "<ul>";
  47. foreach ($_SESSION['tasks'] as $key => $value) {
  48. echo "<li>{$value} <a href=\"{$_SERVER['PHP_SELF']}?delete={$key}\">[Delete]</a></li>";
  49. }
  50. echo "</ul>";
  51. ?>
  52. </body>
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment