note 130232 added to domdocument.registernodeclass
| From: | xq3hfqptzf@cmhvzylmfc.com | Date: | Tue, 08 Apr 2025 09:07:39 +0000 |
| Subject: | note 130232 added to domdocument.registernodeclass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-222070@lists.php.net to get a copy of this message | ||
<?php
session_start();
require_once 'BookManager.php';
// Initialdaten (nur einmal)
if (!isset($_SESSION['books'])) {
$_SESSION['books'] = [
['id' => 1, 'title' => '1984', 'author' =>
'George Orwell', 'year' => 1949],
['id' => 2, 'title' => 'Der Prozess', 'author'
=> 'Franz Kafka', 'year' => 1925],
['id' => 3, 'title' => 'Die Verwandlung',
'author' => 'Franz Kafka', 'year' => 1915]
];
}
$manager = new BookManager($_SESSION['books']);
// CRUD Aktionen
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['create'])) {
$manager->createBook($_POST['title'], $_POST['author'],
(int)$_POST['year']);
}
if (isset($_POST['delete'])) {
$manager->deleteBook((int)$_POST['id']);
}
$_SESSION['books'] = $manager->getAllBooks(); // Session aktualisieren
header("Location: index.php"); // Page refresh
exit();
}
$books = $manager->getAllBooks();
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Buchverwaltung</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body class="bg-light">
<div class="container py-5">
<h1 class="mb-4 text-center">ð Buchverwaltung (Create, Read, Delete
â OOP & Array)</h1>
<!-- Neues Buch hinzufügen -->
<div class="card mb-4">
<div class="card-header">Neues Buch hinzufügen</div>
<div class="card-body">
<form method="post">
<div class="mb-3">
<label class="form-label">Titel</label>
<input type="text" name="title"
class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Autor</label>
<input type="text" name="author"
class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Erscheinungsjahr</label>
<input type="number" name="year"
class="form-control" required>
</div>
<button type="submit" name="create" class="btn
btn-success">Buch hinzufügen</button>
</form>
</div>
</div>
<!-- Tabelle mit allen Büchern -->
<div class="card">
<div class="card-header">Alle Bücher</div>
<div class="card-body p-0">
<table class="table table-striped m-0">
<thead class="table-dark">
<tr>
<th>ID</th>
<th>Titel</th>
<th>Autor</th>
<th>Jahr</th>
<th>Aktion</th>
</tr>
</thead>
<tbody>
<?php foreach ($books as $book): ?>
<tr>
<td><?= $book['id'] ?></td>
<td><?= htmlspecialchars($book['title'])
?></td>
<td><?= htmlspecialchars($book['author'])
?></td>
<td><?= $book['year'] ?></td>
<td>
<form method="post"
style="display:inline">
<input type="hidden" name="id"
value="<?= $book['id'] ?>">
<button type="submit" name="delete"
class="btn btn-sm btn-danger"
onclick="return confirm('Wirklich
löschen?')">Löschen</button>
</form>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($books)): ?>
<tr><td colspan="5"
class="text-center">Keine Bücher vorhanden.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 77.119.207.91)
----
Manual Page -- https://php.net/manual/en/domdocument.registernodeclass.php
Edit -- https://main.php.net/note/edit/130232
Del: integrated -- https://main.php.net/note/delete/130232/integrated
Del: useless -- https://main.php.net/note/delete/130232/useless
Del: bad code -- https://main.php.net/note/delete/130232/bad+code
Del: spam -- https://main.php.net/note/delete/130232/spam
Del: non-english -- https://main.php.net/note/delete/130232/non-english
Del: in docs -- https://main.php.net/note/delete/130232/in+docs
Del: other reasons-- https://main.php.net/note/delete/130232
Reject -- https://main.php.net/note/reject/130232
Search -- https://main.php.net/manage/user-notes.php