34625-vm/add_client.php
Flatlogic Bot 5e6f0c0b7a Inicial
2025-10-03 12:46:21 +00:00

33 lines
1.0 KiB
PHP

<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name']);
if (empty($name)) {
// Handle error: name is required
header('Location: clients.php?error=name_required');
exit;
}
$company_name = trim($_POST['company_name'] ?? '');
$email = trim($_POST['email'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$status = $_POST['status'] ?? 'Active';
$color = $_POST['color'] ?? '#3498db';
$notes = trim($_POST['notes'] ?? '');
try {
$pdo = db_connect();
$sql = "INSERT INTO clients (name, company_name, email, phone, status, color, notes) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $company_name, $email, $phone, $status, $color, $notes]);
header('Location: clients.php?success=client_added');
exit;
} catch (PDOException $e) {
// In a real app, log this error.
header('Location: clients.php?error=db_error');
exit;
}
}
?>