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


            # inscription 

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

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

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


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



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

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

                

            }


        