query("SELECT id, name, company FROM contacts ORDER BY name ASC"); $contacts = $stmt->fetchAll(); } catch (PDOException $e) { $error = "Error fetching contacts: " . $e->getMessage(); $contacts = []; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $title = $_POST['title'] ?? ''; $value = $_POST['value'] ?? 0; $stage = $_POST['stage'] ?? 'Lead'; $contact_id = $_POST['contact_id'] ?? null; $close_date = $_POST['close_date'] ?? null; if (empty($title) || empty($contact_id)) { $error = "Title and contact are required."; } else { try { $stmt = $pdo->prepare("UPDATE deals SET title = :title, value = :value, stage = :stage, contact_id = :contact_id, close_date = :close_date WHERE id = :id"); $stmt->execute([ ':title' => $title, ':value' => $value, ':stage' => $stage, ':contact_id' => $contact_id, ':close_date' => !empty($close_date) ? $close_date : null, ':id' => $id ]); header("Location: index.php?status=deal_updated"); exit; } catch (PDOException $e) { $error = "Database error: " . $e->getMessage(); } } } try { $stmt = $pdo->prepare("SELECT * FROM deals WHERE id = :id"); $stmt->execute([':id' => $id]); $deal = $stmt->fetch(); if (!$deal) { header("Location: index.php"); exit; } } catch (PDOException $e) { echo "Error: " . $e->getMessage(); exit; } $deal_stages = ['Lead', 'Prospecting', 'Qualification', 'Proposal', 'Negotiation', 'Closed Won', 'Closed Lost']; ?>

Edit Deal

Cancel