<?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);
// connect author at mdkhairnar92@gmail.com 
    if (isset($_POST['submit'])) {


        $stmt = $conn->prepare("INSERT INTO `follow_up`(`branch`,`member`,`user`,`category`,`status`) VALUES (?,?,?,?,?)");

         $stmt->execute([
           
           htmlspecialchars($_POST['branch'], ENT_QUOTES, 'UTF-8'),
           htmlspecialchars($_POST['member'], ENT_QUOTES, 'UTF-8'),
           htmlspecialchars($_POST['user'], ENT_QUOTES, 'UTF-8'),
           htmlspecialchars($_POST['category'], ENT_QUOTES, 'UTF-8'),
           htmlspecialchars($_POST['status'], ENT_QUOTES, 'UTF-8'),
          
           
        ]);

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

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

   
// update ....

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

 $stmt = $conn->prepare("UPDATE `follow_up` SET `branch`=?, `member`=?, `user`=?, `category`=?, `status`=?,  WHERE `id`=?");

$stmt->execute([
    htmlspecialchars($_POST['branch'], ENT_QUOTES, 'UTF-8'),
    htmlspecialchars($_POST['member'], ENT_QUOTES, 'UTF-8'),
    htmlspecialchars($_POST['user'], ENT_QUOTES, 'UTF-8'),
    htmlspecialchars($_POST['category'], ENT_QUOTES, 'UTF-8'),
    htmlspecialchars($_POST['status'], ENT_QUOTES, 'UTF-8'),
   
    $_POST['id'] // Assuming you have an 'id' field in your form to identify the record to update
]);
    
        $_SESSION['update'] = "update";
        header("location:../manage_followup.php");
    }
    

    // delete..

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

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

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

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

        header("location:../manage_followup.php");
    }
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
