<?php
   include 'includes/connection.php';
   $sql = mysqli_query($con,"SELECT * FROM `products` where NOT EXISTS (SELECT * FROM stock WHERE stock.product_name=products.id) && business_id=17 && status=1");
   if (mysqli_num_rows($sql)>0) {
   	# code...
   
   while ($result=mysqli_fetch_array($sql)) {
   $productid=$result['id'];
   $product=$result['id'];
   $quantity=$result['quantity'];
   $min_quantity=$result['minimum_quantity'];
   $selling_price=$result['price'];
   $selling_price_whol=$result['price_whole'];
   $branch=$result['branch_id'];
   $business=$result['business_id'];
   $id_user=$result['AddedBy'];
      if (strlen($selling_price_whol)==0) {
       $selling_price_whole=0;
      }else{
        $selling_price_whole=$selling_price_whol;
      }

    $sql2 = mysqli_query($con,"INSERT INTO stock(product_name, selling_price,selling_price_whole,min_quantity,quantity,branch_id,business_id,AddedBy)
    	VALUES('$productid', '$selling_price','$selling_price_whole','$min_quantity','$quantity','$branch','$business','$id_user' )");
    if ($sql2) {
    	echo "yes";
    }else{
    	echo "erro"." ". mysqli_error($con);
    }
   }
   }else{
   	echo 'all done';
   }

   ?>
    <meta http-equiv="refresh" content="0;URL='products.php'" />  
    <?php



?>