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

$login_id = $_SESSION['login'];

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "id")
    $ad_id = $paramValue;
  else if ($paramName == "streetno")
    $streetno = $paramValue;
  elseif ($paramName == "streetname")
    $streetname = $paramValue;
  elseif ($paramName == "streetype") 
    $streetype = $paramValue;  
  elseif ($paramName == "streetdir") 
    $streetdir = $paramValue;  
  elseif ($paramName == "city") 
    $city = $paramValue;  
  elseif ($paramName == "province") 
    $province = $paramValue;  
  elseif ($paramName == "country") 
    $country = $paramValue;  
}

$result = [0, ""];  

$dal = new DAL();
// Get ids to store in Session
$sql = "SELECT id FROM address " .
       "WHERE id = $ad_id " .
       "AND streetno = '$streetno' AND streetname = '$streetname' " .
       "AND streetype = '$streetype' AND streetdir = '$streetdir' " .
       "AND city = '$city' AND province = '$province' " .
       "AND country= '$country' ";
$address = $dal->query($sql);

if (count($address) > 0) {
  $result = [1, "Address exists"];
}    

echo json_encode($result);

?>

