<?php

include $_SERVER['DOCUMENT_ROOT'] . "/classes/autoload.php";
try {
    $client_id = $db->query("clients", "INSERT INTO clients (`name`,`address`,`contact_person`,`contact_number`,`email`,`vat_number`,`reg_number`) VALUES ('{$_POST['name']}','{$_POST['address']}', '{$_POST['contact_person']}', '{$_POST['contact_number']}', '{$_POST['email']}','{$_POST['vat_number']}','{$_POST['reg_number']}')");
    if ($client_id > 0) {
        header("location: home.php");
    }
} catch (Exception $e) {
    if (strpos($e->getMessage(), "Duplicate") !== false) {
        echo "<script>alert('Client already exists!');
        window.location.href = 'home.php';
        </script>";
    }
}