35849-vm/add_task.php
2025-11-19 15:19:42 +00:00

24 lines
657 B
PHP

<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? '';
$description = $_POST['description'] ?? '';
if (!empty($title)) {
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO tasks (title, description) VALUES (?, ?)");
$stmt->execute([$title, $description]);
} catch (PDOException $e) {
header("Location: index.php?error=" . urlencode("Database error: " . $e->getMessage()));
exit;
}
}
header("Location: index.php?success=1");
exit;
} else {
header("Location: index.php");
exit;
}