From 6895c35d62d6ce90db12c5a2cf30851cfd05c3d6 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 7 May 2016 13:39:53 +0200 Subject: [PATCH] Prix de la bière selon quantité --- api/client/payer.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/api/client/payer.php b/api/client/payer.php index aa4b70b..3cef322 100644 --- a/api/client/payer.php +++ b/api/client/payer.php @@ -14,18 +14,23 @@ if (!clientExiste(donne("idCarte"))) { if (donne("quantite")) { $quantite = intval($_POST["quantite"]); - $requete = $db->prepare("SELECT prix FROM Prix"); + $requete = $db->prepare("SELECT prix FROM Prix WHERE produit=?"); if (!$requete) { retour("erreur_bdd_preparee", ["message" => $db->error]); } + $produit = "biere" . $quantite; + $requete->bind_param("s", $produit); $requete->bind_result($prixItem); if (!$requete->execute()) { retour("erreur_bdd", ["message" => $requete->error]); } - $requete->fetch(); + if (!$requete->fetch()) { + retour("produit_inconnu"); + } $requete->close(); - $montant = $prixItem * $quantite; + // $montant = $prixItem * $quantite; + $montant = $prixItem; } else { $montant = floatval($_POST["montant"]); $quantite = 0; -- libgit2 0.21.2