<?php
	session_start();
	require_once 'db_connection.php'; 
	$tempid = $_POST['tempid'];
	$discount = $_POST['discount'];
	$pid = $_POST['pid'];
	$price = $_POST['price'];
	$qty = $_POST['qty'];
	

	
	$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($discount, -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=="%"){
		
	$disrate = intval(substr($discount, 0, -1));
	$dis =  ($price/100)*$disrate;
	$pprice = $price-$dis;
	$distype = 1;
	
}else{
	$pprice = $price-$discount;
	
	$distype = 0;
}











	$sql3 = "UPDATE mobiletemporarycart SET pro_discount='$discount',pro_dis_price='$pprice',discount_type='$distype' WHERE tempid='$tempid'";
	if ($conn->query($sql3) === TRUE) {
		echo "1";
	}else{
		echo 0;
	}

	?>
