<?php 
include("../connection.php");
include("../user.php");
?>
<link rel="stylesheet" href="../css/sweet-alert.css" /> 
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $cur_date = date('Y-m-d H:i:s');
    $user = $_SESSION['user'];
    
    // Retrieve the form input values
    $unit = mysqli_real_escape_string($con, $_POST['unit']);
    $create_measurement = mysqli_query($con, "INSERT INTO `measurement_master`(`name`, `status`, `created_by`, `created_time`) VALUES ('$unit', '0', '$user', '$cur_date')");
    if ($create_measurement) { ?>
        <script>
        setTimeout(function() {
            swal({
                title: "Success",
                text: "Measurement info inserted successfully!",
                type: "success"
            }, function() {
                window.location = "measurement_master.php"; // Redirect after success
            });
        }, 100);
        </script>;
    <?php } 
    else { ?>
        <script>
        setTimeout(function() {
            swal({
                title: "Error",
                text: "Failed to insert Mesurement data!",
                type: "error"
            }, function() {
                window.location = "measurement_master.php"; // Redirect after error
            });
        }, 100);
        </script>;
    <?php }
 }
?>
<script src="../js/sweet-alert.js"></script>
