<?php
ob_start();
session_start();

include 'load.php'; 

    if(isset($_POST['product']) && isset($_POST['qty'])){
       $product =  $_POST['product'];
       $qty =  $_POST['qty'];
       $supplier =  $_POST['supplier'];
       $invoice_no =  $_POST['invoice_no'];
       
       
       if(mysqli_num_rows(mysqli_query($conn, "SELECT * FROM temp_purchase_order WHERE product_id='$product'"))==0){
            $prodductinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileproducts WHERE prid ='$product'"));
            $price = $prodductinfo['price'];
            $sql = "INSERT INTO temp_purchase_order (product_id, qty, price,supplier,invoice_no)VALUES ('$product', '$qty', '$price','$supplier','$invoice_no')";
    
            if ($conn->query($sql) === TRUE) {
                
                    echo "1";
                
            }
       }else{

       }
       

    }

    if(isset($_POST['id'])){
        $id = $_POST['id'];
        $sql = "DELETE FROM temp_purchase_order WHERE temp_purchase_order_id='$id'";
        if ($conn->query($sql) === TRUE) {
            echo "1";
       }
    }



?>