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