34762-vm/add_paper.php
Flatlogic Bot 5235a9fa88 v1
2025-10-07 17:01:46 +00:00

67 lines
2.7 KiB
PHP

<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? '';
$authors = $_POST['authors'] ?? '';
$publication = $_POST['publication'] ?? '';
$year = $_POST['year'] ?? null;
$notes = $_POST['notes'] ?? '';
if ($title && $authors) {
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO papers (title, authors, publication, year, notes) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$title, $authors, $publication, $year, $notes]);
header("Location: /?toast=" . urlencode('Paper added successfully!'));
exit;
} catch (PDOException $e) {
// In a real app, you'd log this error.
header("Location: /add_paper.php?toast=" . urlencode('Error adding paper.'));
exit;
}
}
}
include 'partials/header.php';
?>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="form-container">
<div class="text-center mb-4">
<img src="https://picsum.photos/200" alt="Icon of a document or a book" class="mb-3">
<h2>Add a New Paper</h2>
</div>
<form action="add_paper.php" method="POST" id="add-paper-form">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="mb-3">
<label for="authors" class="form-label">Authors</label>
<input type="text" class="form-control" id="authors" name="authors" required>
</div>
<div class="mb-3">
<label for="publication" class="form-label">Publication/Journal</label>
<input type="text" class="form-control" id="publication" name="publication">
</div>
<div class="mb-3">
<label for="year" class="form-label">Year</label>
<input type="number" class="form-control" id="year" name="year">
</div>
<div class="mb-3">
<label for="notes" class="form-label">Notes</label>
<textarea class="form-control" id="notes" name="notes" rows="4"></textarea>
</div>
<button type="submit" class="btn btn-primary w-100">Add Paper</button>
</form>
</div>
</div>
</div>
</div>
<?php include 'partials/footer.php'; ?>