37237-vm/add_process.php
Flatlogic Bot 4df1537bcb mvp.2
2026-01-02 11:08:19 +00:00

34 lines
1010 B
PHP

<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Basic validation
if (empty(trim($_POST['name'])) || empty(trim($_POST['description']))) {
// Redirect back with an error message if needed, but for now we just exit.
header('Location: index.php?error=emptyfields');
exit;
}
$name = trim($_POST['name']);
$description = trim($_POST['description']);
try {
$pdo = db();
$sql = "INSERT INTO processes (name, description) VALUES (?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $description]);
} catch (PDOException $e) {
// In a real app, log this error. For now, we'll just die.
die("Database error: " . $e->getMessage());
}
// Redirect back to the main page after successful insertion
header('Location: index.php?success=1');
exit;
} else {
// If not a POST request, redirect to the main page
header('Location: index.php');
exit;
}
?>