<?php
session_start();
include '../includes/connection.php';
$product_name=$_GET['product'];
$quantity=$_GET['quantity'];
$unit=$_GET['price'];
$supplier=$_GET['supplier'];
$total_price=$quantity*$unit;
 $id_user=$_SESSION['id'];
$sql = mysqli_query($con,"SELECT max(id) as productid FROM products");
if (mysqli_num_rows($sql) > 0) {
    // output data of each row
    $row = mysqli_fetch_assoc($sql);
      $productid=$row['productid'];
    
} else {
    echo "0 results";
}
$sql1 = mysqli_query($con,"INSERT INTO purchases (product_id, quantity, unit_price, total_price,AddedBy,supplier)
VALUES ('$productid', '$quantity', '$unit', '$total_price','$id_user','$supplier')");

if ($sql1) {
	?>
    <meta http-equiv="refresh" content="0;URL='stock.php'" />  
    <?php
} else {
    echo "Error: " . mysqli_error($con);
}

mysqli_close($con);


?>