<?php
session_start();
include '../../assets/constant/config.php';

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    if (isset($_POST['submit'])) {

// connect author at mdkhairnar92@gmail.com 
        $stmt = $conn->prepare("INSERT INTO `assettype`(`name`,`category`) VALUES (?,?)");

        $stmt->execute([
           
            htmlspecialchars($_POST['name'], ENT_QUOTES, 'UTF-8'),
             htmlspecialchars($_POST['category'], ENT_QUOTES, 'UTF-8'),
        ]);

        $_SESSION['success'] = "success";

        header("location:../manage_assettype.php");
    }

    



// update ....

    if (isset($_POST['update'])) {

 $stmt = $conn->prepare("UPDATE `assettype` SET `name`=?,`category`=? WHERE id=? ");
                  $stmt->execute([
            htmlspecialchars($_POST['name'], ENT_QUOTES, 'UTF-8'),
             htmlspecialchars($_POST['category'], ENT_QUOTES, 'UTF-8'),
           htmlspecialchars($_POST['id'], ENT_QUOTES, 'UTF-8')
        ]);
    
        $_SESSION['update'] = "update";
        header("location:../manage_assettype.php");
    }
    
// connect author at mdkhairnar92@gmail.com 
    // delete ..

    if (isset($_POST['del_id'])) {

        $stmt = $conn->prepare("UPDATE `assettype` SET delete_status='1' where id=? ");

        $stmt->execute([htmlspecialchars($_POST['del_id'], ENT_QUOTES, 'UTF-8')]);

        $_SESSION['delete'] = "delete";

        header("location:../manage_assettype.php");
    }
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
// connect author at mdkhairnar92@gmail.com 