<?php
include("connection.php");

if (isset($_POST['submit'])) {
    $vendor = mysqli_real_escape_string($conn, $_POST['vendor']);
    $traking = mysqli_real_escape_string($conn, $_POST['traking']);
    $status = mysqli_real_escape_string($conn, $_POST['status']);
    $id = $_POST['id'];

    if (($status == "Delivered" || $status == "In transit" ||  $status == "Label created") && empty($traking)) {
        // Agar status "Delivered" ya "In transit" hai aur tracking ID khali hai
        header("Location: pending_order.php?fail=Please Enter Tracking Id !! Than You Select In Transit, Delivered or Label created ");
        exit();
    }

    $sql = "UPDATE new_order SET vendor = '$vendor', traking = '$traking', status = '$status' WHERE id = $id";

    $result = mysqli_query($conn, $sql);

    if ($result) {
        header("Location: pending_order.php?success=Order Updated Successfully!!!");
        exit();
    } else {
        header("Location: pending_order.php?error=Failed insertion!!!");
        exit();
    }
} else {
    header("Location: pending_order.php?error=Not submitted!!!");
    exit();
}
?>
