Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if (!isset($_SESSION['list'])) $_SESSION['list'] = array();
- $action = filter_input(INPUT_GET, "action");
- if ($action == "clear") {
- $_SESSION['list'] = array();
- header("Location: " . $_SERVER['PHP_SELF']);
- }
- $shopItem = strip_tags(filter_input(INPUT_POST, "newItem"));
- if ($shopItem) array_push($_SESSION['list'], $shopItem);
- ?><!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Shopping list</title>
- <style>td, th {
- padding: 0.2em
- }
- </style>
- </head>
- <body>
- <div id ="shopping">
- <form method ="post">
- <input type="text" name ="newItem" placeholder ="New Item" autofocus />
- <input type ="submit" value="Add" />
- </form>
- <a href="?action=clear">Clear list</a>
- <table>
- <thead>
- <tr><th>#</th><th>Item</th></tr>
- </thead>
- <tbody>
- <?php
- foreach ($_SESSION['list'] as $i => $item) echo "\t\t\t\t\t<tr><td>" . ($i + 1) . "</td><td>$item</td></tr>" . PHP_EOL;
- ?>
- </tbody>
- </table>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement