0) { $stmt = db()->prepare("SELECT * FROM startups WHERE id = ? AND founder_id = ?"); $stmt->execute([$startup_id, $_SESSION['user_id']]); $existingStartup = $stmt->fetch(); if (!$existingStartup) { header("Location: startups.php"); exit; } // Check if there is already an active round $stmt = db()->prepare("SELECT id FROM funding_rounds WHERE startup_id = ? AND status = 'Active'"); $stmt->execute([$startup_id]); if ($stmt->fetch()) { header("Location: startup_details.php?id=" . $startup_id); exit; } } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = trim($_POST['name'] ?? ''); $description = trim($_POST['description'] ?? ''); $industry = trim($_POST['industry'] ?? ''); $target = (float)($_POST['funding_target'] ?? 0); $status = $_POST['status'] ?? 'public'; if ((!$existingStartup && (empty($name) || empty($description) || empty($industry))) || $target < 50) { $error = "Please fill in all required fields. Minimum target is £50."; } else { db()->beginTransaction(); try { if ($existingStartup) { // Just create a new round for existing startup $stmt = db()->prepare("INSERT INTO funding_rounds (startup_id, funding_goal, status) VALUES (?, ?, 'Active')"); $stmt->execute([$existingStartup['id'], $target]); $final_id = $existingStartup['id']; } else { // 1. Insert startup $stmt = db()->prepare("INSERT INTO startups (name, description, industry, founder_id, funding_target, status) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$name, $description, $industry, $_SESSION['user_id'], $target, $status]); $new_startup_id = db()->lastInsertId(); // 2. Insert initial funding round $stmt = db()->prepare("INSERT INTO funding_rounds (startup_id, funding_goal, status) VALUES (?, ?, 'Active')"); $stmt->execute([$new_startup_id, $target]); $final_id = $new_startup_id; } db()->commit(); $success = "Funding round is now active!"; header("refresh:2;url=startup_details.php?id=" . $final_id); } catch (PDOException $e) { db()->rollBack(); $error = "Database error: " . $e->getMessage(); } } } $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby'; ?>
= $existingStartup ? 'Set a new funding goal for your existing venture.' : 'Kickstart your project with micro-investments from peers.' ?>