35429-vm/add_project.php
2025-11-02 20:12:50 +00:00

37 lines
1.2 KiB
PHP

<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? null;
$description = $_POST['description'] ?? null;
$client_id = $_POST['client_id'] ?? null;
$status = $_POST['status'] ?? 'Not Started';
$start_date = $_POST['start_date'] ?? null;
$end_date = $_POST['end_date'] ?? null;
if ($name) {
try {
$pdo = db();
$sql = "INSERT INTO projects (name, description, client_id, status, start_date, end_date) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
// Handle empty dates
$client_id = empty($client_id) ? null : $client_id;
$start_date = empty($start_date) ? null : $start_date;
$end_date = empty($end_date) ? null : $end_date;
$stmt->execute([$name, $description, $client_id, $status, $start_date, $end_date]);
header("Location: projects.php?success=1");
exit();
} catch (PDOException $e) {
header("Location: projects.php?error=" . urlencode($e->getMessage()));
exit();
}
} else {
header("Location: projects.php?error=invalid_input");
exit();
}
}
?>