<?php
include 'config.php'; // database connection

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $pid = $_POST['pid'];
    $i_name = $_POST['i_name'];
    $i_number = $_POST['i_number'];
    $i_designation = $_POST['i_designation'];

    // Handle signature upload
    $i_sign = '';
    if (isset($_FILES['i_sign']) && $_FILES['i_sign']['error'] == 0) {
        $targetDir = "uploads/";
        $fileName = basename($_FILES["i_sign"]["name"]);
        $targetFilePath = $targetDir . time() . "_" . $fileName;
        move_uploaded_file($_FILES["i_sign"]["tmp_name"], $targetFilePath);
        $i_sign = $targetFilePath;
    }

    $query = "INSERT INTO police (pid, i_name, i_number, i_designation, i_sign) 
              VALUES ('$pid', '$i_name', '$i_number', '$i_designation', '$i_sign')";

    if (mysqli_query($con, $query)) {
        echo '<script>window.location.href = "police.php";</script>';
    } else {
        echo "Error: " . mysqli_error($con);
    }
}
?>