File "delete_company.php"

Full Path: /home/alphpwcp/previewstream.online/admin/delete_company.php
File size: 539 bytes
MIME-type: text/x-php
Charset: utf-8

<?php
session_start();
if (!isset($_SESSION['admin_id'])) {
    header('Location: login.php');
    exit;
}
include '../db.php';

$id = intval($_GET['id'] ?? 0);

// Only proceed if ID is valid (> 0)
if ($id > 0) {
    // Optional: delete related reviews first to avoid orphan data
    $pdo->prepare("DELETE FROM reviews WHERE company_id = ?")->execute([$id]);

    // Delete the company itself
    $pdo->prepare("DELETE FROM companies WHERE id = ?")->execute([$id]);
}

header('Location: edit_company.php');
exit;
?>