<?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);
        
        $boisson = $inputdata['boisson'];
        $qte = $inputdata['qte'];
        $user = $inputdata['user'];


            # inscription 

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

            $req_user->execute(array($qte, $boisson));

            if ($req_user) {
                $mis=$db->prepare('INSERT INTO stock_boisson(user,boisson,qte,datt) VALUES (?,?,?,?)');
                $mis->execute(array($user, $boisson, $qte,date('Y-m-d')));


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



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

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

                

            }


        