1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| <?php session_start();
include("php/fonction.bdd.php");
$mysqli= connexion_mysql();
$request_method = $_SERVER["REQUEST_METHOD"];
function getProducts($id=0)
{
global $mysqli;
$query = "SELECT * FROM commande_vn ";
if($id != 0)
{
$query .= " WHERE id_cde=".$id." LIMIT 1";
}
$response = array();
$result = mysqli_query($mysqli, $query);
while($row = mysqli_fetch_array($result))
{
$response[] = $row;
}
header('Content-Type: application/json');
echo json_encode($response, JSON_PRETTY_PRINT);
}
function AddProduct()
{
$jsonData = file_get_contents("php://input");
$data = json_decode($jsonData, true);
// echo $data["nom"];
// echo $data->nom;
global $mysqli;
$SOCIETEori = $data["SOCIETEori"];
$DateCommande = $data["DateCommande"];
$PointdeVente = $data["PointdeVente"];
echo $query;
if(mysqli_query($mysqli, $query))
{
$response=array(
'status' => 1,
'status_message' =>'Produit ajoute avec succes.'
);
}
else
{
$response=array(
'status' => 0,
'status_message' =>'ERREUR!.'. mysqli_error($conn)
);
}
header('Content-Type: application/json');
echo json_encode($response);
}
switch($request_method)
{
case 'GET':
if(!empty($_GET["id"]))
{
// Récupérer un seul produit
$id = intval($_GET["id"]);
getProducts($id);
}
else
{
// Récupérer tous les produits
getProducts();
}
break;
default:
// Requête invalide
header("HTTP/1.0 405 Method Not Allowed");
break;
case 'POST':
// Ajouter un produit
AddProduct();
break;
}
?> |