<?php
	session_start();
	require_once 'db_connection.php'; 
	$tempid = $_POST['tempid'];
	$tax = $_POST['tax'];

    $cartitems = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobiletemporarycart WHERE tempid ='$tempid'"));
    	

	$pid = $cartitems['proid'];

    $products = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileproducts WHERE prid ='$pid'"));

	$price = $products['sellprice'];
	$tax1 = $cartitems['tax'];
	

	
	$tempdetails = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileproducts WHERE prid='$pid'"));


	//$tempdetails = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobiletemporarycart WHERE prid='$tempid'"));

	$lastchar = substr($tax, -1); 

	/*if($lastchar=="%"){
		
		$disrate = intval(substr($discount, 0, -1));
		$dis =  ($tempdetails['sellprice']/100)*$disrate;
		$pprice = $tempdetails['sellprice']-$dis;
		$distype = 1;
	}else{
		$pprice = $tempdetails['sellprice']-$discount;
		$distype = 0;
	}
*/

if($lastchar=="%"){
		
	$taxrate = intval(substr($tax, 0, -1));
	$taxtype = 1;
}else{
	$taxrate = $tax;
	
	$taxtype = 0;
}











	$sql3 = "UPDATE mobiletemporarycart SET tax='$taxrate',tax_type='$taxtype' WHERE tempid='$tempid'";
	if ($conn->query($sql3) === TRUE) {
		echo "1";
	}else{
		echo 0;
	}

	?>
