<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "surname")
    $surname = $paramValue;
  else if ($paramName == "firstname")
    $firstname = $paramValue;
  else if ($paramName == "middlename")
    $middlename = $paramValue;
}

$result= [0, "Ok"];

$dal = new DAL();

$sql = "SELECT id FROM contact " .
       "WHERE surname = '$surname' AND firstname = '$firstname' " .
       "AND middlename = '$middlename' LIMIT 1";
$result = $dal->query($sql);

if (null != $result) {
  $name = "$firstname $middlename $surname";
  $result = [1, "Duplicate: $name"];
}
  
echo json_encode($result);

?>

