<?php
include('include/session.php');
// session_start();
include_once('connection.php');
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Create a database connection
$dbConnection = new DbConnection();
$connection = $dbConnection->connection;
if ($connection) {
    // Check if all necessary parameters are set
    if (isset($_GET['order_id'], $_GET['cuid'], $_GET['category'], $_GET['product'], $_GET['variation'], $_GET['price'], $_GET['items'], $_GET['total_price'], $_GET['payment_reference'])) {
        // Extract parameters from the URL
        $order_id = $_GET['order_id'];
        $cuid = $_GET['cuid'];
        $category = $_GET['category'];
        $product = $_GET['product'];
        $variation = $_GET['variation'];
        $price = $_GET['price'];
        $items = $_GET['items'];
        $total_price = $_GET['total_price'];
        $payment_reference = $_GET['payment_reference'];

        // Prepare and execute the SQL queries
        $sql_insert = "INSERT INTO order_cancel (order_id, cuid, category, product, variation, price, items, total_price, payment_reference) 
                        VALUES ('$order_id', '$cuid', '$category', '$product', '$variation', '$price', '$items', '$total_price', '$payment_reference')";

        if (mysqli_query($connection, $sql_insert)) {
            $sql_delete = "DELETE FROM order_summery WHERE order_id = '$order_id'";

            if (mysqli_query($connection, $sql_delete)) {
                  echo "<script> alert('Cancel Successful'); window.location.href = '_new_order_list.php'; </script>";
               
            } else {
                // Handle the case when data deletion fails
                echo "Error deleting data from the current table: " . mysqli_error($connection);
            }
        } else {
            // Handle the case when data insertion fails
            echo "Error inserting data into the 'cancel_order' table: " . mysqli_error($connection);
        }
    } else {
        // Handle the case when all required parameters are not present
        echo "Invalid request. Missing parameters.";
    }
} else {
    echo "Database connection failed.";
}
?>






















