<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');
 
foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "id")
    $in_id = $paramValue;
  else if ($paramName == "name")
    $name = $paramValue;
  else if ($paramName == "type_id")
    $type_id = $paramValue;
}

$dal = new DAL(); 
 
if ($in_id == 0) {
  $sql = "INSERT INTO instrument " .
         "(name, type_id) " .
         "VALUES ('$name', $type_id) ";
  $in_id = $dal->query($sql);
}

else {
  $sql = "UPDATE instrument " .
         "SET name='$name', type_id=$type_id " .
         "WHERE id = $in_id ";
  $result = $dal->query($sql);
}

echo json_encode($in_id);

?>

