<?php 
require_once 'config.php';
$error=false;
$errors=array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   
  
   $user_id=$_POST['user_id'];
   $product_id=$_POST['product_id'];
   $ratings=$_POST['ratings'];
   $review=$_POST['review_comment'];
	$rowcount=0;
		 $sql12="SELECT id FROM product_reviews where user_id=".$user_id." AND product_id =".$product_id;
		 if ($result12=mysqli_query($con,$sql12)){			 
			  $rowcount12=mysqli_num_rows($result12);
				if($rowcount12>0){
					$errors['success']=false;
					$errors['message']='You have already ratted this product';
				}else{
					$createitem=mysqli_query($con,"INSERT INTO product_reviews (user_id,product_id,ratting,reviews,status) VALUES('".$user_id."','".$product_id."','".$ratings."','".$review."',1)");
					if($createitem){
					$errors['success']=true;
					$errors['messages']='Ratting added Sucessfully';
					}else{
						$errors['success']=false;
					$errors['message']='something wrong';
					}
					
				}
		}
		
	/* if($createitem){
		 $sql="SELECT id FROM product_reviews where user_id=".$user_id." AND product_id =".$product_id;;

			if ($result=mysqli_query($con,$sql)){			 
			  $rowcount=mysqli_num_rows($result);			  
			  }
	     	$errors['reviews']=$rowcount;
	     	$errors['success']=true;
	     	$errors['messages']='Item added to cart Sucessfully';
	 }else{
	     $errors['success']=false;
	     $errors['message']='You have already ratted this product';
	 }*/
 	 
	 	echo json_encode($errors);
}