37487-vm/add_bug.php
2026-01-15 17:13:40 +00:00

77 lines
2.9 KiB
PHP

<?php
require_once 'db/config.php';
$title = $description = $steps_to_reproduce = '';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title'] ?? '');
$description = trim($_POST['description'] ?? '');
$steps_to_reproduce = trim($_POST['steps_to_reproduce'] ?? '');
if (empty($title)) {
$errors[] = 'Title is required.';
}
if (empty($errors)) {
try {
$pdo = db();
$stmt = $pdo->prepare('INSERT INTO bugs (title, description, steps_to_reproduce) VALUES (?, ?, ?)');
$stmt->execute([$title, $description, $steps_to_reproduce]);
header('Location: bugs.php');
exit;
} catch (PDOException $e) {
$errors[] = 'Database error: ' . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add New Bug</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { background-color: #f8fafc; }
</style>
</head>
<body>
<div class="container py-5">
<h1 class="h3 mb-4">Add New Bug</h1>
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<?php foreach ($errors as $error): ?>
<p class="mb-0"><?php echo $error; ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="card">
<div class="card-body">
<form action="add_bug.php" method="POST">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" value="<?php echo htmlspecialchars($title); ?>" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="5"><?php echo htmlspecialchars($description); ?></textarea>
</div>
<div class="mb-3">
<label for="steps_to_reproduce" class="form-label">Steps to Reproduce</label>
<textarea class="form-control" id="steps_to_reproduce" name="steps_to_reproduce" rows="5"><?php echo htmlspecialchars($steps_to_reproduce); ?></textarea>
</div>
<div class="d-flex justify-content-end">
<a href="bugs.php" class="btn btn-secondary me-2">Cancel</a>
<button type="submit" class="btn btn-primary">Submit Bug</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>