prepare($sql); $stmt->execute([$name, $description]); $process_id = $pdo->lastInsertId(); // Insert process steps if available if (isset($_POST['steps']) && is_array($_POST['steps'])) { $step_order = 0; $stmt_steps = $pdo->prepare("INSERT INTO process_steps (process_id, title, description, step_order) VALUES (?, ?, ?, ?)"); foreach ($_POST['steps'] as $step) { if (isset($step['title']) && isset($step['description'])) { $stmt_steps->execute([$process_id, $step['title'], $step['description'], $step_order]); $step_order++; } } } } catch (PDOException $e) { // In a real app, log this error. For now, we'll just die. error_log("DB Error: " . $e->getMessage()); header('Location: index.php?error=dberror'); exit; } // Redirect back to the main page after successful insertion header('Location: index.php?success=processadded'); exit; } else { // If not a POST request, redirect to the main page header('Location: index.php'); exit; } ?>