<?php
include '../db/db.php';
session_start();
$log= htmlspecialchars(trim($_SESSION['user']), ENT_QUOTES, 'UTF-8');
if (empty($log)) {
	 
  $redirectUrl = "../index.php";
  echo "<script type=\"text/javascript\">";
  echo "window.location.href = '$redirectUrl'";
  echo "</script>";
	 
}else{

  $sqlu="SELECT * FROM details_of_users WHERE user='$log' and val='1'";
  $resultu=mysqli_query($conn, $sqlu);
  $countu=mysqli_num_rows($resultu);
  
	if($countu==1){
		
		$id = htmlspecialchars(trim($_GET['id']), ENT_QUOTES, 'UTF-8');
		$s_name= htmlspecialchars(trim($_POST['name']), ENT_QUOTES, 'UTF-8');
		$address= htmlspecialchars(trim($_POST['address']), ENT_QUOTES, 'UTF-8');
		$nic= htmlspecialchars(trim($_POST['nic']), ENT_QUOTES, 'UTF-8');
		$mobile= htmlspecialchars(trim($_POST['mobile']), ENT_QUOTES, 'UTF-8');
		$tp= htmlspecialchars(trim($_POST['tp']), ENT_QUOTES, 'UTF-8');
		$note= htmlspecialchars(trim($_POST['note']), ENT_QUOTES, 'UTF-8');
		$v_code = htmlspecialchars(trim($_POST['v_code']), ENT_QUOTES, 'UTF-8');
		$acc_no = htmlspecialchars(trim($_POST['acc_no']), ENT_QUOTES, 'UTF-8');
		

			mysqli_query($conn, "UPDATE account_posting SET PName='$s_name' WHERE L_Code='$acc_no'");
			
			mysqli_query($conn, "UPDATE supplier SET name='$s_name', address='$address', nic='$nic', mobile='$mobile', tp='$tp', note='$note', vender_code='$v_code' WHERE id='$id'");

			echo "<script>alert('Successfully Updated!')</script>";
			$redirectUrl = "../add_supplier.php";
			echo "<script type=\"text/javascript\">";
			echo "window.location.href = '$redirectUrl'";
			echo "</script>"; 

	
	} else{
	  $redirectUrl = "../index.php";
	  echo "<script type=\"text/javascript\">";
	  echo "window.location.href = '$redirectUrl'";
	  echo "</script>";
	
	}
}

?>