<?php
require_once __DIR__ . '/../../connect.php';

$driverID = filterRequest("driverID");
$name = filterRequest("name");
$licenseClass = filterRequest("licenseClass");
$documentNo = filterRequest("documentNo");
$address = filterRequest("address");
$height = filterRequest("height");
$postalCode = filterRequest("postalCode");
$sex = filterRequest("sex");
$stateCode = filterRequest("stateCode");
$expireDate = filterRequest("expireDate");
$dateOfBirth = filterRequest("dateOfBirth");

$sql = "INSERT INTO `lisenceDetails`(`id`,`driverID`, `name`, `licenseClass`, `documentNo`, `address`, `height`, `postalCode`, `sex`, `stateCode`, `expireDate`, `dateOfBirth`) VALUES (
  UUID(),
  :driverID
  :name,
  :licenseClass,
  :documentNo,
  :address,
  :height,
  :postalCode,
  :sex,
  :stateCode,
  :expireDate,
  :dateOfBirth
)";

$stmt = $con->prepare($sql);
$stmt->bindParam(':driverID', $driverID);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':licenseClass', $licenseClass);
$stmt->bindParam(':documentNo', $documentNo);
$stmt->bindParam(':address', $address);
$stmt->bindParam(':height', $height);
$stmt->bindParam(':postalCode', $postalCode);
$stmt->bindParam(':sex', $sex);
$stmt->bindParam(':stateCode', $stateCode);
$stmt->bindParam(':expireDate', $expireDate);
$stmt->bindParam(':dateOfBirth', $dateOfBirth);
$stmt->execute();

if ($stmt->rowCount() > 0) {
  // Print a success message
  jsonSuccess($message = "Data saved successfully");
} else {
  // Print a failure message
  jsonError($message = "Failed to save data");
}
?>