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

    $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'"));

	$productprice = $products['sellprice'];
	$qty = $cartitems['pro_qty'];
	$costprice = $products['price'];
	if($costprice > $price){
		$price = $productprice;		
	}

	
	$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'"));


	/*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($cartitems['proid']==148){
    $sql3 = "UPDATE mobiletemporarycart SET pro_price = $price WHERE tempid='$tempid'";
	if ($conn->query($sql3) === TRUE) {
		echo "1";
	}else{
		echo 0;
	}
}else{
    $qprice = $price / $productprice;
	$qty = 1 * $qprice;
	$sql3 = "UPDATE mobiletemporarycart SET pro_price = $price,pro_qty = $qty WHERE tempid='$tempid'";
	if ($conn->query($sql3) === TRUE) {
		echo "1";
	}else{
		echo 0;
	}
}

   







	?>
