36998-vm/add_project.php
Flatlogic Bot ce816a917b beta
2025-12-16 14:45:12 +00:00

35 lines
1.0 KiB
PHP

<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['project_name'] ?? '');
$client = trim($_POST['client_name'] ?? '');
$start_date = trim($_POST['start_date'] ?? '');
if (empty($name) || empty($start_date)) {
// Basic validation
// In a real app, you would have a more robust error handling/messaging system
header('Location: index.php?error=validation');
exit;
}
try {
$pdo = db();
$sql = "INSERT INTO projects (name, client, start_date) VALUES (?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $client, $start_date]);
} catch (PDOException $e) {
// Proper error logging should be implemented
// For now, redirect with a generic error
header('Location: index.php?error=db');
exit;
}
header('Location: index.php?success=added');
exit;
} else {
// If not a POST request, redirect home
header('Location: index.php');
exit;
}