:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/kreative_crm/quatation/**
:: Editing File: delete_inward.php
<?php // Include database connection and session management include 'db.php'; include_once("session.php"); // --- Input Validation --- // Check that a numeric ID was provided in the URL query string if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { $_SESSION['error'] = "Invalid request: No valid Inward ID provided."; header("Location: inward_list.php"); // Redirect to the list page exit; } // Sanitize and cast the ID to an integer for security $inward_id = (int)$_GET['id']; // --- Database Transaction --- // Start a transaction to ensure all related deletions (if any) succeed or fail together mysqli_begin_transaction($conn); try { // SQL to delete the main inward entry. // NOTE: If you have related tables (e.g., inward_items), they must either have // ON DELETE CASCADE defined in the database schema, or you must add // explicit DELETE statements for those related records before this one. $sql = "DELETE FROM inward WHERE id = $inward_id"; if (!mysqli_query($conn, $sql)) { // If the query fails, throw an exception to trigger the rollback throw new Exception("Inward entry delete failed: " . mysqli_error($conn)); } // If the deletion was successful, commit the transaction mysqli_commit($conn); $_SESSION['success'] = "Inward entry deleted successfully."; header("Location: inward_list.php"); exit; } catch (Exception $e) { // If any exception occurred (including query failure), roll back the transaction mysqli_rollback($conn); $_SESSION['error'] = "Error deleting Inward entry: " . $e->getMessage(); header("Location: inward_list.php"); exit; } ?>