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 83 84 85 86 87 88 89 90 91 92 93
|
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="fr">
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Suppression</title>
<link rel="stylesheet" media="screen" type="text/css" title="Design" href="mycss.css" />
</head>
<body style="margin: 0%;">
<?php
if (!isset($_SESSION['slogin']))
{
echo"<script LANGUAGE='JavaScript'>document.location.href='index.php'</script>";
}
?>
<div id="Titre">
<p style="font-size: 2em; margin-top: 0%; margin-bottom: 0%; text-align: center; color: rgb(51, 51, 51);">Mon site</p>
<p id="menubis">
<dl>
<dt><a href="destroy.php" target="Fcorps">Déconnexion</a></dt><dt>compte:<?php echo " ". $_SESSION['slogin']; ?></dt>
</dl>
</p>
</div>
<br>
<br>
<br>
<div id="Corps">
<p class="Banderole">SUPPRESSION</p>
<?php
$Zone= htmlspecialchars($_GET['zone']);
$Code= htmlspecialchars($_GET['code']);
if ($Zone=='equipements' or $Zone=='ateliers')
{
//Je me connecte à information_schema
try { $id_db = new PDO('mysql:host=localhost;dbname=information_schema', $_SESSION['slogin'], $_SESSION['spasswd']
,array(PDO::ATTR_PERSISTENT => true)); }
catch(Exception $e){ die('Erreur : '.$e->getMessage()); }
//je cherche le nom du champ identifiant ou champ clé de la table
$req = $id_db->prepare("SELECT COLUMN_NAME FROM COLUMNS WHERE TABLE_SCHEMA='mabd' and TABLE_NAME=:Zone and COLUMN_KEY= 'PRI'");
$req->execute(array('Zone'=> $Zone));
$ligne = $req->fetch();
$Ki= $ligne[0];
echo $Ki; //c'est le champ clé, je suppose qu'il y en a un seul, il apparait donc tout marche jusqu'ici
$req->closecursor();
$id_db = null; //Je ferme la connexion
//Je me connecte à ma bd
try { $id_db2 = new PDO('mysql:host=localhost;dbname=mabd', $_SESSION['slogin'], $_SESSION['spasswd']
,array(PDO::ATTR_PERSISTENT => true)); }
catch(Exception $e){ die('Erreur : '.$e->getMessage()); }
//Je récolte toutes les clés présente dans la table
$req = $id_db2->prepare('SELECT :Ki FROM :Zone');
$req->execute(array('Ki'=> $Ki, 'Zone'=>$Zone));
while($ligne=$req->fetch())
{
echo $ligne[0];
$Mescodes[] = $ligne[0];
}
$req->closecursor();
//Je vérifie que la clé passé en paramètre fait partie des clés de la table
if (in_array($Code, $Mescodes))
{
//Je cherche l'enregistrement à supprimer pour montrer à l'utilisateur ce qu'il est sur le point de supprimer
$req = $id_db2->prepare('SELECT * FROM :Zone WHERE :Ki= :Code');
$req->execute(array('Zone'=> $Zone, 'Ki'=> $Code));
$ligne = $req->fetch();
?>
<table id="Maliste"><caption><strong>ELEMENTS A SUPPRIMER</strong></caption><tbody>
<?php
foreach($ligne as $cle => $element)
{
echo '<tr><td>'.$cle.'</td>'.'<td>'.$element.'</td></tr>';
}
?>
</tbody></table>
<?php
//Suite du code...
}
else die("Paramètres incorrects!!");
}
else die("Paramètres incorrects!")
?>
<br />
<br />
</div>
<div id="Pied"> Copyright Bric &
Brac, 2010</div>
</body></html> |
Partager