33 lines
1.0 KiB
PHP
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;
|
|
}
|
|
}
|
|
?>
|