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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| <!doctype html>
<html>
<head>
<meta charset="ISO-8859-1" />
<title>Test du SGBD MySql !</title>
<link rel="stylesheet" type="text/css" href="../Styles.css" />
</head>
<body>
<h1>Test du SGBD MySql !</h1>
<?php
/*------------------------*/
/* On récupére les champs */
/*------------------------*/
$reponse = "";
$saisie = false;
$datenreg = "";
extract ($_POST);
require_once("MySql_In.php");
/*------------------------------------------------------------*/
/* Recherche du plus haut Identifiant dans la table "clients" */
/*------------------------------------------------------------*/
if ($saisie == false)
{
if (($nom == "") and ($prenom == ""))
$reponse = "Veuillez saisir le nom et le prénom !";
else
{
$requete1 = "select MAX(ID) as MAX from tab_clients";
try {
$sql1 = $link->query($requete1);
$enreg = $sql1->fetch(PDO::FETCH_OBJ);
$nbre = $enreg->MAX;
}
catch ( Exception $e )
{
echo "Une erreur est survenue dans la requète select 1 : ", $e->getMessage();
die();
}
$sql1->closeCursor();
$id = $nbre + 1;
/*---------------------------------------------*/
/* initialisation à la date et l'heure du jour */
/*---------------------------------------------*/
$datenreg = date('Y-m-d H:i:s');
/*-----------------------------------*/
/* Insertion dans la table "clients" */
/*-----------------------------------*/
try {
$ins = $link->prepare("INSERT INTO `tab_clients` (`id`, `nom`, `prenom`, `naissance`, `ville`, `datenreg`) VALUES (:param1, :param2, :param3, :param4, :param5, :param6)");
$ins->bindParam('param1', $id);
$ins->bindParam('param2', $nom);
$ins->bindParam('param3', $prenom);
$ins->bindParam('param4', $naissance);
$ins->bindParam('param5', $ville);
$ins->bindParam('param6', $datenreg);
$ins->execute();
}
catch ( Exception $e ) {
echo "Une erreur est survenue dans la requète insert : ", $e->getMessage();
die();
}
}
}
?>
<table>
<tr><th>ID</th><th>NOM</th><th>PRENOM</th><th>DATE DE NAISSANCE</th><th>VILLE</th><th>DATE ENREGISTREMENT</th></tr>
<?php
/*------------------------------*/
/* Vidage de la table 'clients' */
/*------------------------------*/
$requete2 = "SELECT * FROM tab_clients";
try {
$sql2 = $link->query($requete2);
while ($enreg = $sql2->fetch(PDO::FETCH_OBJ))
{
echo "<tr><td>$enreg->id</td>";
echo "<td>$enreg->nom</td>";
echo "<td>$enreg->prenom</td>";
echo "<td>$enreg->naissance</td>";
echo "<td>$enreg->ville</td>";
echo "<td>$enreg->datenreg</td></tr>";
}
$sql2->closeCursor();
}
catch ( Exception $e )
{
echo "Une erreur est survenue dans la requète select 2 : ", $e->getMessage();
die();
}
require_once("MySql_Out.php");
?>
</table>
<?php
/*------------------*/
/* Message d'erreur */
/*------------------*/
if ($reponse != "")
echo "<div id=\"reponse\">$reponse</div>";
?>
</body>
</html> |
Partager