prepare('SELECT * FROM contacts WHERE id = ?'); $stmt->execute([$id]); $contact = $stmt->fetch(); if ($contact) { $name = $contact['name']; $email = $contact['email']; } else { die('Contact not found.'); } } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = $_POST['name'] ?? ''; $email = $_POST['email'] ?? ''; if (empty($name) || empty($email)) { $error = 'Name and email are required.'; } else { if ($is_edit) { $stmt = db()->prepare('UPDATE contacts SET name = ?, email = ? WHERE id = ?'); $stmt->execute([$name, $email, $id]); } else { $stmt = db()->prepare('INSERT INTO contacts (name, email) VALUES (?, ?)'); $stmt->execute([$name, $email]); } header('Location: contacts.php'); exit; } } ?>