prepare(" SELECT s.*, fr.id as round_id, fr.funding_goal, fr.funding_raised, fr.status as round_status, s.founder_id as founder_id FROM startups s LEFT JOIN funding_rounds fr ON s.id = fr.startup_id AND fr.status = 'Active' WHERE s.id = ? "); $stmt->execute([$startupId]); $startup = $stmt->fetch(); if (!$startup) { die("Startup not found."); } if ($startup['round_status'] !== 'Active') { die("This startup does not have an active funding round."); } $remaining = (float)($startup['funding_goal'] - $startup['funding_raised']); $error = ''; $success = ''; // Get investor's current balance $stmt = db()->prepare("SELECT balance FROM users WHERE id = ?"); $stmt->execute([$_SESSION['user_id']]); $investor_balance = (float)$stmt->fetchColumn(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $amount = (float)($_POST['amount'] ?? 0); $investor_id = $_SESSION['user_id']; if ($amount <= 0) { $error = "Please enter a valid investment amount."; } elseif ($amount > $investor_balance) { $error = "Insufficient funds in your money pot. Please add funds first. You currently have £" . number_format($investor_balance, 2) . "."; } elseif ($amount > $remaining && $remaining > 0) { $error = "The investment amount (£" . number_format($amount) . ") exceeds the remaining funding goal of £" . number_format($remaining) . "."; } else { db()->beginTransaction(); try { // 1. Create investment record $equity_pct = 0.00; // Mock logic for equity $stmt = db()->prepare("INSERT INTO investments (startup_id, investor_id, funding_round_id, amount, equity_pct, status) VALUES (?, ?, ?, ?, ?, 'approved')"); $stmt->execute([$startupId, $investor_id, $startup['round_id'], $amount, $equity_pct]); // 2. Update funding_rounds raised amount $stmt = db()->prepare("UPDATE funding_rounds SET funding_raised = funding_raised + ? WHERE id = ?"); $stmt->execute([$amount, $startup['round_id']]); // 3. Update startup total raised $stmt = db()->prepare("UPDATE startups SET funding_raised = funding_raised + ? WHERE id = ?"); $stmt->execute([$amount, $startupId]); // 4. TRANSFER MONEY: Investor pot -> Founder pot // Deduct from investor $stmt = db()->prepare("UPDATE users SET balance = balance - ? WHERE id = ?"); $stmt->execute([$amount, $investor_id]); // Add to founder $stmt = db()->prepare("UPDATE users SET balance = balance + ? WHERE id = ?"); $stmt->execute([$amount, $startup['founder_id']]); // 5. Log transactions $stmt = db()->prepare("INSERT INTO wallet_transactions (user_id, amount, type, description) VALUES (?, ?, 'investment_out', ?)"); $stmt->execute([$investor_id, $amount, "Investment in " . $startup['name']]); $stmt = db()->prepare("INSERT INTO wallet_transactions (user_id, amount, type, description) VALUES (?, ?, 'investment_in', ?)"); $stmt->execute([$startup['founder_id'], $amount, "Investment received from investor for " . $startup['name']]); db()->commit(); $success = "Investment of £" . number_format($amount) . " confirmed successfully! Funds moved to the founder's pot."; header("refresh:3;url=portfolio.php"); } catch (Exception $e) { db()->rollBack(); $error = "Error: " . $e->getMessage(); } } } $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby'; ?> Invest in <?= htmlspecialchars($startup['name']) ?> | <?= htmlspecialchars($platformName) ?>

Back

You are participating in the active funding round for this startup.

Your Wallet Balance
£
Add Funds
Funding Goal £
Already Raised £
Remaining £
Back to Startup Profile