01.
02.
03.
04.
05.
06.
07.
08.
09.
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.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
|
|
<?php
/******************************************************************************/
/* */
/* __ ____ */
/* ___ / / ___ / __/__ __ _____________ ___ */
/* / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-< */
/* / .__/_//_/ .__/___/\___/\_,_/_/ \__/\__/___/ */
/* /_/ /_/ */
/* */
/* */
/******************************************************************************/
/* */
/* Titre : Template Case à Cocher pour ajouter/supp/modifier des... */
/* */
/* URL : http://www.phpsources.org/scripts486-PHP.htm */
/* Auteur : PhpSources */
/* Date édition : 09 Jan 2009 */
/* Website auteur : http://www.phpsources.org */
/* */
/******************************************************************************/
/*
CREATE TABLE articles (
id_article int(5) NOT NULL auto_increment,
nom_article varchar(80) NOT NULL default '',
description_article text NOT NULL,
PRIMARY KEY (id_article)
) ENGINE=MyISAM;
#
# Contenu de la table `articles`
#
INSERT INTO articles VALUES (1, 'maison campagne', 'garage;terrasse');
INSERT INTO articles VALUES (3, 'maison ville', 'chambres;garage;terrasse');
INSERT INTO articles VALUES (3, 'maison plage', 'chambres;garage');
*/
/********************************/
/* */
/* CONNECTION - EXECUTION */
/* */
/********************************/
$mabasededonnee="test";
$connection = mysql_connect("localhost","root","");
// test la connection
if ( ! $connection )
die ("connection impossible");
// Connecte la base
mysql_select_db($mabasededonnee) or die ("pas de connection");
/********************************/
/* */
/* AJOUTER MODIFIER SUPP */
/* */
/********************************/
if ($_POST['ajouter_sql']) {
// passe le tableau en chaine de caractere
$chaine_etat = implode(";", $_POST['etat']);
mysql_query("INSERT INTO articles (nom_article,description_article)
VALUES('".$_POST['nom_sql']."','".$chaine_etat."')");
echo mysql_error();
echo 'Ajout terminé !! <br /><br />';
}
if ($_POST['modifier_sql']) {
// passe le tableau en chaine de caractere
$chaine_etat = implode(";", $_POST['etat']);
mysql_query("UPDATE articles SET nom_article='".$_POST['nom_sql']."',
description_article ='".$chaine_etat."'
WHERE id_article ='".$_POST['id_sql']."'");
echo 'Modification terminé !! <br /><br />';
}
if ($_GET['supprimer'] == 'ok') {
mysql_query("DELETE FROM articles
WHERE id_article='".$_GET['id']."'");
echo 'Suppression terminé !! <br /><br />';
}
/********************************/
/* */
/* formulaire de modification */
/* */
/********************************/
if ($_GET['modifier'] == 'ok') {
$q = mysql_query("SELECT * FROM articles WHERE id_article = ".$_GET['id']."");
$r = mysql_fetch_array($q);
// repasse la chaine en tableau
$chaine2_etat = explode(";", $r['description_article']);
?>
Modifier l' article avec l'id : <?php echo $id;?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="hidden" name="id_sql" value="<?php echo $id; ?>">
<input name="nom_sql" type="text" value="<?php echo $r['nom_article'];?>">
<br />
Etat actuel <strong>: <?php echo $r['description_article'];?> </strong>
<br />
<?php if (in_array("chambres",$chaine2_etat)) $check = "checked"; else $check = '';?>
<input name="etat[]" type="checkbox" value="chambres" <?php echo $check;?>>chambres
<?php if (in_array("garage",$chaine2_etat)) $check = "checked"; else $check = '';?>
<input name="etat[]" type="checkbox" value="garage" <?php echo $check;?>>garage
<?php if (in_array("terrasse",$chaine2_etat)) $check = "checked"; else $check = '';?>
<input name="etat[]" type="checkbox" value="terrasse" <?php echo $check;?>>terrasse
<input type="submit" name="modifier_sql" value="Modifier">
</form>
<?php }
/********************************/
/* */
/* formulaire d'ajout */
/* */
/********************************/
elseif ($_GET['ajouter'] == 'ok') {
?> Ajouter 1 nouvelle article
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input name="nom_sql" type="text">
<input name="etat[]" type="checkbox" value="chambres" checked>chambres
<input name="etat[]" type="checkbox" value="garage">garage
<input name="etat[]" type="checkbox" value="terrasse">terrasse
<input type="submit" name="ajouter_sql" value="Ajouter">
</form> <?php
}
/********************************/
/* */
/* Lecture des enregistrements */
/* */
/********************************/
else {
$q = mysql_query("SELECT * FROM articles");
while ($r = mysql_fetch_array($q)) {
$nom = $r['nom_article'];
$etat = $r['description_article'];
$id = $r['id_article'];
echo '<strong>'.$nom.'</strong><br />';
echo ' => ';
echo '<a href="'.$_SERVER['PHP_SELF'].'?modifier=ok&id='.$id.'">Modifier</a>'.' - ';
echo '<a href="'.$_SERVER['PHP_SELF'].'?supprimer=ok&id='.$id.'">Supprimer</a>';
echo '<br />';
}
echo '<br />';
echo '<a href="'.$_SERVER['PHP_SELF'].'?ajouter=ok">Ajouter</a>';
}
?>
|