remAnimal.php 1.22 KB
Newer Older
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
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
<html>
<head>
  <title>Exercice</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
<body>
  <?php
    $vHost = 'tuxa.sme.utc';
    $vPort = '5432';
    $vData = 'dbbdd0p117';
    $vUser = 'bdd0p117';
    $vPass = 'LpIHl1sZ';

    try{
      $vConn = new PDO("pgsql:host=$vHost;port=$vPort;dbname=$vData", $vUser, $vPass);
    } catch(PDOException $e){
      echo "Erreur de connection '$e'";
    }

    try{
      $idAnimal = $_POST['idAnimal'];
      //TODO Valider que l'id reçu existe
      if($idAnimal != ""){
          $vSql ="DELETE FROM posologie P  WHERE P.traitement IN (SELECT idTraitement FROM traitement WHERE idAnimal='$idAnimal');";
          $vSt = $vConn->prepare($vSql);
          $vSt->execute();

          $vSql ="DELETE FROM traitement WHERE idAnimal='$idAnimal';";
          $vSt = $vConn->prepare($vSql);
          $vSt->execute();

          $vSql ="DELETE FROM animal WHERE idAnimal='$idAnimal';";
          $vSt = $vConn->prepare($vSql);
          $vSt->execute();

          header('Location: http://tuxa.sme.utc/~bdd0p117/animal.php');
      }else
        echo "Il manque une donnée";
    } catch(PDOException $e){
      echo "Erreur de suppresion '$e'";
    }


  ?>
</body>
</html>