<?php
session_start();

if(!isset($_SESSION['user_id']))
{
    header("Location: /beauty_pos/login.php");
    exit;
}

include_once "../config/database.php";

if(!isset($_GET['id']) || !is_numeric($_GET['id']))
{
    header("Location: index.php");
    exit;
}

$id=(int)$_GET['id'];

$check=mysqli_query($conn,"
SELECT id
FROM promo_codes
WHERE id='$id'
LIMIT 1
");

if(mysqli_num_rows($check)==0)
{
    $_SESSION['error']="Promo code not found.";
    header("Location: index.php");
    exit;
}

mysqli_query($conn,"
DELETE FROM promo_codes
WHERE id='$id'
");

$_SESSION['success']="Promo code deleted successfully.";

header("Location: index.php");
exit;
?>