36543-vm/create_project.php
Flatlogic Bot 4c235f6179 hell yea
2025-12-01 12:52:33 +00:00

66 lines
2.3 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
$title = '';
$description = '';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title'] ?? '');
$description = trim($_POST['description'] ?? '');
if (empty($title)) {
$error = 'Project title is required.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO projects (title, description) VALUES (?, ?)");
$stmt->execute([$title, $description]);
$_SESSION['message'] = 'Project created successfully!';
header("Location: projects.php");
exit;
} catch (PDOException $e) {
$error = "Database error: " . $e->getMessage();
}
}
}
include 'includes/header.php';
?>
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h1 class="h3 mb-0">Create a New Project</h1>
</div>
<div class="card-body">
<?php if ($error): ?>
<div class="alert alert-danger">
<?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<form action="create_project.php" method="POST">
<div class="mb-3">
<label for="title" class="form-label">Project 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">Project Description</label>
<textarea class="form-control" id="description" name="description" rows="5"><?php echo htmlspecialchars($description); ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Create Project</button>
<a href="projects.php" class="btn btn-secondary">Cancel</a>
</form>
</div>
</div>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>