<?php
session_start();
    header('Access-Control-Allow-Origin:*');
    header('Content-Type; application/json; charset=utf-8');
    header('Access-control-Allow-Method: POST');
    header('Access-control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-request-With');
    include('db.php');
        $inputdata = json_decode(file_get_contents("php://input"), true);
        
        $user = $inputdata['user'];
        $matiere_premiere = $inputdata['matiere_premiere'];
        $qte = $inputdata['qte'];
        


            # inscription 

            $up=$db->prepare('UPDATE matiere_premiere SET qte_stock=qte_stock+? WHERE id=?');

            $up->execute(array($qte, $matiere_premiere));

            if ($up) {
                $mis=$db->prepare('INSERT INTO stock_matiere_premiere(user,matiere_premiere,qte) VALUES (?,?,?)');
                $mis->execute(array($user, $matiere_premiere, $qte));


                echo (json_encode(['response' => 1]));



            }else{
                // création non réussie

                echo (json_encode(['response' => 0]));

                

            }


        