<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST");

require_once "config.php";

$json = file_get_contents("php://input");
$data = json_decode($json);

$name = $data->name;
$year = $data->year;
$month = $data->month;
$date = $data->date;
$hour = $data->hour;
$minute = $data->minute;

$conn = connect_db();

$res = array();

if ($conn->connect_error) {
	die('Connection failed: ' . $conn->connect_error);
} else {
	$sql = "
		INSERT INTO `submission`
		(name, dob)
		VALUES
		(
			'" . $name . "',
			'" . $year . "-" . $month . "-" . $date . " " . $hour . ":" . $minute . ":00'
		)
	";

	if ($conn->query($sql) === TRUE) {
		$res["success"] = "Submit Successful";
	} else {
		$res["failed"] = "Submit Failed";
	}
}

$conn->close();
echo json_encode($res);
