vidange.php
1.06 KB
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
<?php
require_once("../commun.php");
verifierDroit(2);
if (!(donne("idCarte"))) {
retour("requete_malformee");
}
if (!clientExiste(donne("idCarte"))) {
retour("client_inconnu");
}
$requete = $db->prepare("SELECT solde FROM Clients WHERE idCarte=?");
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
$requete->bind_param("s", $_POST["idCarte"]);
$requete->bind_result($soldeAncien);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->fetch();
$requete->close();
if ($soldeAncien <= 0) {
retour("solde_negatif");
}
$requete = $db->prepare("UPDATE Clients SET solde=0 WHERE idCarte=?");
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
$requete->bind_param("s", $_POST["idCarte"]);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->close();
$idTransaction = transaction(TRANSACTION_VIDANGE, $_POST["idCarte"], $soldeAncien);
retour("ok", ["idTransaction" => $idTransaction, "soldeAncien" => $soldeAncien]);
?>