Commit 6895c35d62d6ce90db12c5a2cf30851cfd05c3d6
1 parent
5464dee3
Prix de la bière selon quantité
Showing
1 changed file
with
8 additions
and
3 deletions
Show diff stats
api/client/payer.php
@@ -14,18 +14,23 @@ if (!clientExiste(donne("idCarte"))) { | @@ -14,18 +14,23 @@ if (!clientExiste(donne("idCarte"))) { | ||
14 | 14 | ||
15 | if (donne("quantite")) { | 15 | if (donne("quantite")) { |
16 | $quantite = intval($_POST["quantite"]); | 16 | $quantite = intval($_POST["quantite"]); |
17 | - $requete = $db->prepare("SELECT prix FROM Prix"); | 17 | + $requete = $db->prepare("SELECT prix FROM Prix WHERE produit=?"); |
18 | if (!$requete) { | 18 | if (!$requete) { |
19 | retour("erreur_bdd_preparee", ["message" => $db->error]); | 19 | retour("erreur_bdd_preparee", ["message" => $db->error]); |
20 | } | 20 | } |
21 | + $produit = "biere" . $quantite; | ||
22 | + $requete->bind_param("s", $produit); | ||
21 | $requete->bind_result($prixItem); | 23 | $requete->bind_result($prixItem); |
22 | if (!$requete->execute()) { | 24 | if (!$requete->execute()) { |
23 | retour("erreur_bdd", ["message" => $requete->error]); | 25 | retour("erreur_bdd", ["message" => $requete->error]); |
24 | } | 26 | } |
25 | - $requete->fetch(); | 27 | + if (!$requete->fetch()) { |
28 | + retour("produit_inconnu"); | ||
29 | + } | ||
26 | $requete->close(); | 30 | $requete->close(); |
27 | 31 | ||
28 | - $montant = $prixItem * $quantite; | 32 | + // $montant = $prixItem * $quantite; |
33 | + $montant = $prixItem; | ||
29 | } else { | 34 | } else { |
30 | $montant = floatval($_POST["montant"]); | 35 | $montant = floatval($_POST["montant"]); |
31 | $quantite = 0; | 36 | $quantite = 0; |