
<?php
session_start();
include '../includes/connection.php';
$branch=$_SESSION['branch_id'];
$business=$_SESSION['business_id'];
$sql = "SELECT distinct(product_name) as pname from products where NOT EXISTS (SELECT product_name from stores where stores.product_name=products.product_name) AND business_id='$business'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $product_name=$row['pname'];
        $user_id=$_SESSION['id'];

        
        




$sqlst = mysqli_query($con,"INSERT INTO stores(product_name,business_id,recorded_by) VALUES('$product_name','$business','$user_id')");


if ($sqlst) {
    
} else {
    echo "Error: Error" . $sqlst . "<br>" . mysqli_error($con);
}

//mysqli_close($con);



//insert data


    }
} else {
    echo mysqli_error($con);
}

//mysqli_close($conn);
?>




<?php
//delete everything from temp table

// Create connection

// sql to delete a record

if (mysqli_query($conn, $sql)) {
   echo "<script> window.location='store.php';</script>";
   
    
} else {
    echo "Error deleting record: " . mysqli_error($conn);
}

mysqli_close($conn);
?>