prepare("DELETE FROM customers WHERE id = ?"); $stmt->execute([$delete_id]); header("Location: customer.php"); exit; } // Handle form submission for adding a new customer if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_customer'])) { $companyName = $_POST['companyName'] ?? ''; $contactPerson = $_POST['contactPerson'] ?? ''; $email = $_POST['email'] ?? ''; $phone = $_POST['phone'] ?? ''; if (!empty($companyName)) { $pdo = db(); $stmt = $pdo->prepare("INSERT INTO customers (companyName, contactPerson, email, phone) VALUES (?, ?, ?, ?)"); $stmt->execute([$companyName, $contactPerson, $email, $phone]); header("Location: customer.php"); exit; } } // Handle form submission for updating a customer if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_customer'])) { $id = $_POST['customer_id']; $companyName = $_POST['companyName'] ?? ''; $contactPerson = $_POST['contactPerson'] ?? ''; $email = $_POST['email'] ?? ''; $phone = $_POST['phone'] ?? ''; if (!empty($id) && !empty($companyName)) { $pdo = db(); $stmt = $pdo->prepare("UPDATE customers SET companyName = ?, contactPerson = ?, email = ?, phone = ? WHERE id = ?"); $stmt->execute([$companyName, $contactPerson, $email, $phone, $id]); header("Location: customer.php"); exit; } } // Fetch all customers $pdo = db(); $stmt = $pdo->query("SELECT * FROM customers ORDER BY createdAt DESC"); $customers = $stmt->fetchAll(); include 'includes/header.php'; ?>