<?php 
date_default_timezone_set("Asia/Bangkok");
require_once 'config.php';
$error=false;
$errors=array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   
  
   $user_id=$_POST['user_id'];
   $product_id=$_POST['product_id'];
   $amount=$_POST['amount'];
   $transaction_id='trendinfo_'.mt_rand(100000,999999);
   $payment_type=$_POST['payment_type'];  
   $address=$_POST['address'];
   $city=$_POST['city'];
   $state=$_POST['state'];
   $pincode=$_POST['pincode'];
   $floor=$_POST['floor'];
   $unit_no=$_POST['unit_no'];
      $country=$_POST['country'];
   
   
 $cat=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM users WHERE id=".$user_id));
  

		$createitem=mysqli_query($con,"INSERT INTO orders (user_id,product_id,amount,transaction_id,payment_type,floor,unit_no,address,city,country,pincode,
		status) VALUES('".$user_id."','".$product_id."','".$amount."','".$transaction_id."','".$payment_type."','".$floor."','".$unit_no."','".$address."','".$city."','".$country."','".$pincode."',1)");
	 if($createitem){
		 $errors['orderid']=mysqli_insert_id($con);
		 mysqli_query($con,'DELETE FROM cart_items WHERE user_id='.$user_id);
		
		 
	     	
	     	$errors['status']=true;
	     	$errors['order']=mysqli_insert_id($con);
	     	$errors['message']='Order Created Sucessfully';
	 }else{
		 $errors['status']=false;
	     $errors['message']='Somthing went wrong !!';
	 }
  
 	 
	 	echo json_encode($errors);
}