Liste - PHP Online
Form of PHP Sandbox
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Liste.php
- <!DOCTYPE html>
- <html>
- <head>
- <title>Liste erstellen, bearbeiten und speichern</title>
- </head>
- <body>
- <h1>Liste erstellen, bearbeiten und speichern</h1>
- <form action="list.php" method="post">
- <label for="item">Eintrag hinzufügen:</label>
- <input type="text" id="item" name="item">
- <input type="submit" name="add" value="Hinzufügen">
- </form>
- <br>
- <?php
- // Laden der Liste aus der Datei
- $list = array();
- $file = "list.txt";
- if (file_exists($file)) {
- $list = unserialize(file_get_contents($file));
- }
- if (isset($_POST['item'])) {
- if (isset($_POST['add'])) {
- array_push($list, $_POST['item']);
- }
- if (isset($_POST['edit'])) {
- $index = $_POST['index'];
- $list[$index] = $_POST['item'];
- }
- if (isset($_POST['delete'])) {
- $index = $_POST['index'];
- unset($list[$index]);
- }
- // Speichern der Liste in der Datei
- file_put_contents($file, serialize($list));
- }
- foreach ($list as $index => $item) {
- echo $item . " ";
- echo "<form action='list.php' method='post'>";
- echo "<input type='hidden' name='index' value='$index'>";
- echo "<input type='text' name='item' value='$item'>";
- echo "<input type='submit' name='edit' value='Bearbeiten'>";
- echo "<input type='submit' name='delete' value='Löschen'>";
- echo "</form>";
- echo "<br>";
- }
- ?>
- </body>
- </html>
File Description
- Liste
- PHP Code
- 22 Jan-2023
- 1.49 Kb
You can Share it:
Latest PHP Pastes