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 129 130
|
<?php
/************************************************************/
/* Structure de la table : */
/*----------------------------------------------------------*/
/* CREATE TABLE `fser` ( */
/* `id` tinyint(3) NOT NULL auto_increment, */
/* `nom` varchar(50) NOT NULL default '', */
/* `prenom` varchar(50) NOT NULL default '', */
/* `adresse` text NOT NULL, */
/* `code_postal` int(10) NOT NULL default '0', */
/* `ville` varchar(50) NOT NULL default '', */
/* `telephone` varchar(25) NOT NULL default '', */
/* `portable` varchar(25) NOT NULL default '', */
/* `email` varchar(100) NOT NULL default '', */
/* UNIQUE KEY `id` (`id`) */
/* ) TYPE=MyISAM AUTO_INCREMENT=27 ; */
/* */
/************************************************************/
$db = mysql_connect('localhost', 'root', '');
mysql_select_db('annuaire',$db);
if(isset($_POST['modifier'])) {
$id = $_POST['modifier'];
$maj= "UPDATE `fser` SET `nom` = '$nom2',`prenom` = 'prenom2',`adresse` = '$adresse2',`code_postal` = '$cp2',`ville` = '$ville2',`telephone` = '$num2',`portable` = '$port2',`email` = '$email2' WHERE `id` ='$id'";
mysql_query($maj) or die('erreur'.mysql_error());
echo '<br>Mise a jour effectuée avec succes.';
}
if(isset($_POST['ajouter'])) {
$add = "INSERT INTO `fser` ( `id` , `nom` , `prenom` , `adresse` , `code_postal` , `ville` , `telephone` , `portable` , `email` )
VALUES (
'', '$nom', '$prenom', '$adresse', '$cp', '$ville', '$num', '$port', '$email')";
mysql_query($add);
echo " vous avez bien ajouté $prenom $nom";
}
echo "<p><a href='annu.php?action=modifier'>Ajouter un contact</a><br><a href='annu.php?action=lire'>Votre annuaire</a></p>\n";
if($_GET['action']=="lire") {
$requete = "select * from fser order by nom ASC";
$ex = mysql_query($requete);
if(mysql_num_rows($ex) == 0) { die("Votre carnet est vide.<br><a href='annu.php?action=modifier'>Ajouter un contact</a>"); }
else {
while($tab = mysql_fetch_array($ex))
{
$id = $tab['id'];
$nom = $tab['nom'];
$prenom = $tab['prenom'];
$adresse = $tab['adresse'];
$cp = $tab['code_postal'];
$ville = $tab['ville'];
$num = $tab['telephone'];
$port = $tab['portable'];
$email = $tab['email'];
echo "<div align=\"center\">\n";
echo "<table border=1 align=\"center\" width=40%>\n <tr>\n";
echo " <td>$id</td>\n <td>$nom</td>\n <td>$prenom</td>\n </tr>\n";
echo " <tr>\n <td colspan=3>$adresse</td>\n </tr>\n";
echo " <tr>\n <td>$cp</td><td colspan=2>$ville</td>\n </tr>\n";
echo " <tr>\n <td>$num</td><td>$port</td><td><a href=\"mailto:$email\">email</a></td>\n </tr>\n</table>\n";
echo "<p>| <a href=\"annu.php?action=modifier&id=$id\">Modifier les informations</a> | <a href=\"annu.php?action=supprimer&id=$id\">Supprimer</a> |</p>\n";
}
echo "</div>\n";
}
}
elseif(($_GET['action']=="modifier")) {
if(isset($_GET['id'])) {
$requete = "select * from fser where id='".$_GET['id']."'";
$ex = mysql_query($requete);
$tab = mysql_fetch_array($ex);
$id = $tab['id'];
$nom = $tab['nom'];
$prenom = $tab['prenom'];
$adresse = $tab['adresse'];
$cp = $tab['code_postal'];
$ville = $tab['ville'];
$num = $tab['telephone'];
$port = $tab['portable'];
$email = $tab['email'];
echo "<form name=\"modif\" method=\"post\">\n";
echo "<div align=\"center\">\n";
echo "<input name=\"modifier\" type=\"hidden\" value=\"$id\">\n";
echo "<input name=\"action\" type=\"hidden\" value=\"action\">\n";
echo "<table border=1 align=\"center\" width=40%><tr>\n";
echo "<td><input name=\"id2\" type=\"text\" value=\"$id\";></td><td><input name=\"nom2\" type=\"text\" value=\"$nom\"></td><td><input name=\"prenom2\" type=\"text\" value=\"$prenom\"></td></tr>\n";
echo "<tr><td colspan=3><input name=\"adresse2\" type=\"text\" value=\"$adresse\" size=45></td></tr>\n";
echo "<tr><td><input name=\"cp2\" type=\"text\" value=\"$cp\"></td><td colspan=2><input name=\"ville2\" type=\"text\" value=\"$ville\"></td></tr>\n";
echo "<tr><td><input name=\"num2\" type=\"text\" value=\"$num\"></td><td><input name=\"port2\" type=\"text\" value=\"$port\"></td><td><input name=\"email2\" type=\"text\" value=\"$email\"></td></tr>\n</table>\n";
echo "<input type=\"submit\" value=\"Mettre a jour\">\n";
echo "</form>\n<br>\n";
}
else {
echo "<form name=\"ajouer\" method=\"post\">\n";
echo "<div align=\"center\">\n";
echo "<input name=\"ajouter\" type=\"hidden\" >\n";
echo "<table border=1 align=\"center\" width=40%><tr>\n";
echo "<td colspan=2><input name=\"nom\" type=\"text\" value=\"nom\"></td><td><input name=\"prenom\" type=\"text\" value=\"prenom\"></td></tr>\n";
echo "<tr><td colspan=3><input name=\"adresse\" type=\"text\" value=\"adresse\" size=45></td></tr>\n";
echo "<tr><td><input name=\"cp\" type=\"text\" value=\"copde postal\"></td><td colspan=2><input name=\"ville\" type=\"text\" value=\"ville\"></td></tr>\n";
echo "<tr><td><input name=\"num\" type=\"text\" value=\"telephone\"></td><td><input name=\"port\" type=\"text\" value=\"portable\"></td><td><input name=\"email\" type=\"text\" value=\"email\"></td></tr>\n</table>\n";
echo "<input type=\"submit\" value=\"Ajouter !\">\n";
echo "</form>\n<br>\n";
} }
elseif(($_GET['action']=="supprimer")) {
if(isset($_GET['id'])) {
$id = $_GET['id'];
echo "Etes vous sûr de vouloir supprimer ce contact ?\n";
echo "<a href=\"annu.php?action=supprimer&confirm=1&id=$id\">oui</a>\n";
echo "<a href=\"annu.php?action=supprimer&confirm=0&id=$id\">non</a>\n";
if($_GET['confirm']==1) {
$sup = "DELETE from fser where id='$id'";
mysql_query($sup) or die('<br>'.mysql_error());
echo "<br>vous avez bien supprimé ce contact.";
}elseif($_GET['confirm']=="0") {
echo "<br>vous n'avez pas supprimé.";
}
}
}
?> |
Partager