<?php 
require_once 'config.php';
$error=false;
$errors=array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //$json = file_get_contents('php://input');

// Converts it into a PHP object
/*$data = json_decode($json);
  
   $user_id=$data->user_id;
   $product_id=$data->product_id;
   $quantity=$data->quantity;*/
    $user_id=$_POST['user_id'];
   $product_id=$_POST['product_id'];
   $quantity=$_POST['quantity'];
  $rowcount=0;
  //echo "UPDATE cart_items SET quantity ='".$quantity."' WHERE user_id = '".$user_id."' AND product_id ='".$product_id."'";die;
		$createitem=mysqli_query($con,"UPDATE cart_items SET quantity ='".$quantity."' WHERE user_id = '".$user_id."' AND product_id ='".$product_id."'");
	 if($createitem){
		 $sql="SELECT id FROM cart_items where user_id=".$user_id;

			if ($result=mysqli_query($con,$sql)){			 
			  $rowcount=mysqli_num_rows($result);			  
			  }
	     	$errors['cartitems']=$rowcount;
	     	$errors['status']=true;
	     	$errors['message']='Item Updated to cart Sucessfully';
	 }else{
	     $errors['status']=false;
	     $errors['message']='Somthing went wrong !!';
	 }
 	 
	 	echo json_encode($errors);
}