<?php
include '../includes/connection.php';
session_start();
$id_user=$_SESSION['id'];
$business=$_SESSION['business_id'];

$sql = mysqli_query($con,"SELECT * FROM products where id=(select max(id) from products) and AddedBy='$id_user' and business_id='$business'");
if (mysqli_num_rows($sql) > 0) {
    // output data of each row
    $row = mysqli_fetch_assoc($sql);
      $productid=$row['id'];
      $selling_price=$row['price'];
      $min_quantity=$row['minimum_quantity'];
      $branch=$row['branch_id'];
    $sql2 = mysqli_query($con,"INSERT INTO stock(product_name, selling_price,min_quantity,branch_id,business_id,AddedBy)
    	VALUES('$productid', '$selling_price','$min_quantity','$branch','$business','$id_user' )");
    if($sql2){
    	?><meta http-equiv="refresh" content="0;URL='product_admin.php'" /> <?php
    }
} else {
    echo "0 results";
}


?>