<?php
	session_start();
    include_once"includes/conn.php";
    include_once"functions/Success.php";
    include_once"functions/Error.php";

    if (isset($_POST['Submit'])) {
    	$SN = mysqli_real_escape_string($conn,strip_tags($_POST['SN']));
    	$SA = mysqli_real_escape_string($conn,strip_tags($_POST['SA']));
    	$Snum = mysqli_real_escape_string($conn,strip_tags($_POST['Snum']));
    	$RN = mysqli_real_escape_string($conn,strip_tags($_POST['RN']));
    	$RA = mysqli_real_escape_string($conn,strip_tags($_POST['RA']));
    	$Rnum = mysqli_real_escape_string($conn,strip_tags($_POST['Rnum']));
    	$DL = mysqli_real_escape_string($conn,strip_tags($_POST['DL']));
    	$PD = mysqli_real_escape_string($conn,strip_tags($_POST['PD']));
    	$AD = mysqli_real_escape_string($conn,strip_tags($_POST['AD']));
    	$Wgt = mysqli_real_escape_string($conn,strip_tags($_POST['Wgt']));
    	$Qty = mysqli_real_escape_string($conn,strip_tags($_POST['Qty']));
    	$Amt = mysqli_real_escape_string($conn,strip_tags($_POST['Amt']));
    	$TC = mysqli_real_escape_string($conn,strip_tags($_POST['TC']));
        $FT = mysqli_real_escape_string($conn,strip_tags($_POST['FT']));
	
		
	
	
		/*?echo $SN.$SA.$Snum.$RN.$RA.$Rnum.$DL.$PD.$AD.$Wgt.$Qty.$Amt.$TC.$FT;*/
    	if (empty($SN) || empty($SA) || empty($Snum) || empty($RN) || empty($RA) || empty($Rnum) || empty($DL) || empty($PD) || empty($AD) || empty($Wgt) || empty($Qty) || empty($Amt) || empty($TC) ) {
    		$_SESSION['er'] = 'emp';
		
			header('Location: Add-Shipment.php?rr=1');
    	}else{
			$sql = "SELECT * FROM details";
		 $result = mysqli_query($conn, $sql);
		 if (mysqli_num_rows($result)>0) {
			 while ($rows = mysqli_fetch_assoc($result)) {
				 $Tcode = $rows['TrackNum']; 
			 }
			 if ($TC === $Tcode) {
				 header('Location: Add-Shipment.php?rh=1');
			 }else{
				$sql0 = "INSERT INTO details (SN, SA, Snum, RN, RA, Rnum, DL, PD, AD, Weight, Qty, Amt, TrackNum,Mode, Held) VALUES('$SN','$SA', '$Snum', '$RN', '$RA', '$Rnum', '$DL', '$PD', '$AD', '$Wgt', '$Qty', '$Amt', '$TC', '$FT', 'Pending')";
    				$res0 = mysqli_query($conn, $sql0);
    				if ($res0) {
    					$_SESSION['suc'] = 'Added';
                        header('Location: Add-Shipment.php?rt=1');
    				}
				}
			}
		}

	}

