36766-vm/delete_shipment_details.php
Flatlogic Bot 6c14b2436f 2.0
2025-12-18 09:40:37 +00:00

37 lines
1.0 KiB
PHP

<?php
require_once 'db/config.php';
session_start();
if (!isset($_SESSION['user_id']) || (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) && empty($_SESSION['dealer_id'])) {
header('Location: login.php');
exit;
}
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
header('Location: service_requests.php');
exit;
}
$shipment_id = $_GET['id'];
try {
$pdo = db();
// Get the service_request_id before deleting
$stmt_get_id = $pdo->prepare("SELECT service_request_id FROM shipment_details WHERE id = ?");
$stmt_get_id->execute([$shipment_id]);
$service_request_id = $stmt_get_id->fetchColumn();
if ($service_request_id) {
$stmt_delete = $pdo->prepare("DELETE FROM shipment_details WHERE id = ?");
$stmt_delete->execute([$shipment_id]);
header("Location: service_request_details.php?id=$service_request_id");
} else {
header('Location: service_requests.php');
}
exit;
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}