Bonjour à tous !
Je voudrais créer un système équivalent à une news qui utilise une fonction modification et suppression avec une demande confirmation.
Je me suis bloqué sur la page de récupération de données à modifier, et il me reste aussi la page de suppression.
Voici le code de ma table :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 # ----------------------------------------------------------------------------- # TABLE: REAL_ # ----------------------------------------------------------------------------- DROP TABLE IF EXISTS `real_`; CREATE TABLE `REAL_` ( id INT NOT NULL AUTO_INCREMENT, AUTEUR VARCHAR(255) NOT NULL, DATE DATETIME NOT NULL, TITRE VARCHAR(255) NULL, DEPARTEMENT VARCHAR(255) NOT NULL, PROGRAMME_PROJET VARCHAR(255) NOT NULL, AXE_STRATEGIQUE VARCHAR(255) NOT NULL, RAPPEL TEXT NOT NULL, REALISATION TEXT NOT NULL, IMPACT TEXT NOT NULL, SUITE TEXT NOT NULL, OBSERVATION TEXT NOT NULL, TSIAHY TEXT NOT NULL, ZAVA_BITA TEXT NOT NULL, TRAIKA TEXT NOT NULL, TOHINY TEXT NOT NULL, MARIKA TEXT NOT NULL, PRIMARY KEY (id) ) TYPE=MyISAM AUTO_INCREMENT=39 ;
La page de configuration connexion.inc.php
Voici la page d’ajout index.php et ça fonctionne bien. C’est OK
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 <? $serveur = "localhost"; $login = "root"; $bdd = "real_"; $mdp = ""; $connexion = mysql_connect($serveur,$login,$mdp); $db = mysql_select_db($bdd, $connexion); ?>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <html> <head> <title>Index du champ d'ajout</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form action="ajouter.php" method="post" > <table width="87%" border="0"> <tr> <td width="26%">Auteur</td> <td width="2%">:</td> <td width="72%"><input type="text" name="auteur" maxlength="100" size="76"></td> </tr> <tr> <td>Date</td> <td>:</td> <td> <input type="datetime" name="date"> (aaaa-mm-jj)</td> </tr> <tr> <td>Titre</td> <td>:</td> <td><input type="text" name="titre" maxlength="1000" size="76"> </td> </tr> <tr> <td>Departement</td> <td>:</td> <td> <input type="text" name="departement" maxlength="1000" size="76"> </td> </tr> <tr> <td height="27">Programme/projet</td> <td>:</td> <td><input type="text" name="programme_projet" maxlength="1000" size="76"> </td> </tr> <tr> <td>Axe strategique</td> <td>:</td> <td> <input type="text" name="axe_strategique" maxlength="1000" size="76"> </td> </tr> <tr> <td><strong>VERSION FRANCAISE</strong></td> <td> </td> <td> </td> </tr> <tr> <td>Rappel du projet</td> <td>:</td> <td> <textarea name="rappel" cols=70 rows=3 ></textarea> </td> </tr> <tr> <td>Réalisation</td> <td>:</td> <td> <textarea name="realisation" cols=70 rows=3></textarea> </td> </tr> <tr> <td>Impact</td> <td>:</td> <td> <textarea name="impact" cols=70 rows=3></textarea> </td> </tr> <tr> <td>Suite éventuelle<br></td> <td>:</td> <td> <textarea name="suite" cols=70 rows=3></textarea> </td> </tr> <tr> <td>Observations</td> <td>:</td> <td><textarea name="observation" cols=70 rows=3></textarea> </td> </tr> <tr> <td><strong>VERSION MALAGASY</strong></td> <td> </td> <td> </td> </tr> <tr> <td>Fampatsiahivana tetikasa</td> <td>:</td> <td><textarea name="tsiahy" cols=70 rows=3></textarea> </td> </tr> <tr> <td>Zava-bita</td> <td>:</td> <td><textarea name="zava_bita" cols=70 rows=3></textarea> </td> </tr> <tr> <td>Fiantraikany<br></td> <td>:</td> <td><textarea name="traika" cols=70 rows=3></textarea> </td> </tr> <tr> <td><font size="3">Ny mety ho tohin ny asa sy ny fanatsarana azy</font><br></td> <td>:</td> <td><textarea name="tohiny" cols=70 rows=3></textarea> </td> </tr> <tr> <td>Fanamarihana <br></td> <td>:</td> <td> <textarea name="marika" cols=70 rows=3></textarea> </td> </tr> </table> <center><input type="Submit" value="Poster la réalisation"></center> </form> </body> </html>
La page d’envoi ajouter.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Renvoi les données rempli</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <? // On commence par la récupération des champs function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } //Déclaration de tous les variables $auteur=$_POST['auteur']; $date=$_POST['date']; $titre=$_POST['titre']; $departement=$_POST['departement']; $programme_projet=$_POST['programme_projet']; $axe_strategique=$_POST['axe_strategique']; $rappel=$_POST['rappel']; $realisation=$_POST['realisation']; $impact=$_POST['impact']; $suite=$_POST['suite']; $observation=$_POST['observation']; $tsiahy=$_POST['tsiahy']; $zava_bita=$_POST['zava_bita']; $traika=$_POST['traika']; $tohiny=$_POST['tohiny']; $marika=$_POST['marika']; // connexion à la base de donnée $hostname = "localhost"; $database = "real_"; $username = "root"; $password = ""; $site = mysql_pconnect($hostname, $username, $password) or die(mysql_error()); // on créer la requête SQL, pour ensuite l'envoyer $insertSQL = "INSERT INTO `real` ( `id` , `AUTEUR` , `DATE` , `TITRE` , `DEPARTEMENT` , `PROGRAMME_PROJET` , `AXE_STRATEGIQUE` , `RAPPEL` , `REALISATION` , `IMPACT` , `SUITE` , `OBSERVATION` , `TSIAHY` , `ZAVA_BITA` , `TRAIKA` , `TOHINY` , `MARIKA` ) VALUES ('', '$auteur','$date','$titre','$departement','$programme_projet', '$axe_strategique','$rappel', '$realisation', '$impact', '$suite', '$observation', '$tsiahy','$zava_bita', '$traika', '$tohiny', '$marika')"; mysql_select_db($database, $site); $Result1 = mysql_query($insertSQL, $site) or die(mysql_error()); //mysql_query($requete); if ($Result1) { echo "Vos données ont été envoyées !"; } else { echo "erreur !"; } // fermeture de la connexion vers Mysql mysql_close(); /* function date_fr($date=0) { if(!$date) $date=date("Y-m-d H:i:s"); //Timestamp courant par défaut $a = substr($date, 0, 4); $m = substr($date, 5, 2); $j = substr($date, 8, 2); $h = substr($date, 11, 2); $min = substr($date, 14, 2); $s = substr($date, 17, 2); $datefr=$j.'/'.$m.'/'.$a; $heurefr=$h.':'.$min; return array("date"=>$datefr,"heure"=>$heurefr); } //Exemple d'utilisation: $date = date_fr(); echo "Nous sommes le ".$date["date"]."<br />"; echo "Il est ".$date["heure"]; */ ?> </body> </html>
Voici la page d’affichage du formulaire recup.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <html> <head> <title>Récuperation de données remplies</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <? // Utilisation de la fonction include pour le paramètre de connexion include('connexion.inc.php') ; // connexion au serveur mysql mysql_select_db("real_",$connexion); // récupération des données de la table real $requete = "SELECT * FROM `real` ORDER BY `DATE` ASC LIMIT 0 , 10 "; //envoi de la requete $envoi = mysql_query($requete); // boucle qui fait tourner dans toutes les tableaux while($tableau = mysql_fetch_row($envoi)) { // declaration de tous les variables $id = $tableau[0]; $auteur = $tableau[1]; $date = $tableau[2]; $titre = $tableau[3]; $departement = $tableau[4]; $programme_projet = $tableau[5]; $axe_strategique = $tableau[6]; $rappel = $tableau[7]; $realisation = $tableau[8]; $impact = $tableau[9]; $suite = $tableau[10]; $observation = $tableau[11]; $tsiahy = $tableau[12]; $zava_bita = $tableau[13]; $traika = $tableau[14]; $tohiny = $tableau[15]; $marika = $tableau[16]; // transition date us => fr $annee_date = substr($date,0,4); $mois_date = substr($date,5,2); $jour_date = substr($date,8,2); $date = "$jour_date-$mois_date-$annee_date"; // affichage des données de la base echo '<b> Postée le : '.$date.' par : '.$auteur.'</b><br> '; echo '<i>Le titre de la réalisation : '.$titre.'</i><br>'; echo 'Departement :<b> <i>'.$departement.'</b></i><br>'; echo 'Programme/Projet :<b> <i>'.$programme_projet.'</b></i><br>'; echo 'Axe Strategique :<b> <i>'.$axe_strategique.'</b></i><br>'; echo '<b><u>REALISATIONS :</u></b><br>'; echo 'Rappel du projet :<b> <i>'.$rappel.'</b></i><br>'; echo 'Réalisation :<b> <i>'.$realisation.'</b></i><br>'; echo 'Impact <b> <i>'.$impact.'</b></i><br>'; echo 'Suite eventuelle :<b> <i>'.$suite.'</b></i><br>'; echo 'Observation :<b> <i>'.$observations.'</b></i><br>'; echo '<b><u>ZAVA-BITA :</u></b><br>'; echo 'Fampahatsiahivana ilay tetikasa:<b> <i>'.$tsiahy.'</b></i><br>'; echo 'Zava-bita :<b> <i>'.$zava_bita.'</b></i><br>'; echo 'Fiantraikany :<b> <i>'.$traika.'</b></i><br>'; echo 'Ny mety ho tohin\'ny asa sy ny fanatsarana azy :<b> <i>'.$tohiny.'</b></i><br>'; echo 'Fanamarihana:<b> <i>'.$marika.'</b></i> <br>'; echo '<a href="modification1.php?id='.$id.'">Modifier</a> '; echo '<a href="suppression1.php?id='.$id.'">Supprimer</a> <br><br>'; } ?> </body> </html>
La page de récupération des données à modifier modification1.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
131
132
133
134
135 <html> <head> <title>Page de modification de Réalisation</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <? // Utilisation de la fonction include pour le paramètre de connexion include('connexion.inc.php') ; // connexion au serveur mysql mysql_select_db("real_",$connexion); // récupération des données de la table real $requete = "SELECT * FROM `real` WHERE 1 AND `id` = ". $_GET['id']." LIMIT 0 , 10"; //$requete = " SELECT * FROM real WHERE id=". $_GET['id']; echo "requette".$requete; //envoi de la requete $envoi = mysql_query($requete); // test d'affichage de id //echo $_GET['id']; while($tableau = mysql_fetch_row($envoi)) { ?> <form name="Misajour" action="modification2.php" method="GET" > <input type="hidden" name="id" value="<?php echo $tableau[0]; ?>"/> <table width="87%" border="0"> <tr> <td width="26%">Auteur</td> <td width="2%">:</td> <td width="72%"><input type="text" name="auteur" maxlength="100" size="76" value="<?php echo $tableau[1]; ?>"> </td> </tr> <tr><td>Date</td> <td>:</td> <td> <input type="datetime" name="date" value="<?php echo $tableau[2] ?>"> (aaaa-mm-jj)</td> </tr> <tr> <td>Titre</td> <td>:</td> <td><input type="text" name="titre" maxlength="1000" size="76" value="<?php echo $tableau[3] ;?>"> </td> </tr> <tr> <td>Departement</td> <td>:</td> <td> <input type="text" name="departement" maxlength="1000" size="76" value="<?php echo $tableau[4] ;?>"> </td> </tr> <tr> <td height="27">Programme/projet</td> <td>:</td> <td><input type="auteur" name="auteur" maxlength="100" size="76" value="<?php echo $tableau[5] ?>"> <input type="text" name="programme_projet" maxlength="1000" size="76" value="<?php echo $tableau[6] ;?>"> </td> </tr> <tr> <td>Axe strategique</td> <td>:</td> <td> <input type="text" name="axe_strategique" maxlength="1000" size="76" value="<?php echo $tableau[7]; ?>"> </td> </tr> <tr> <td><strong>VERSION FRANCAISE</strong></td> <td> </td> <td> </td> </tr> <tr> <td>Rappel du projet</td> <td>:</td> <td> <textarea name="rappel" cols=70 rows=3 value="<?php echo $tableau[8]; ?>"></textarea> </td> </tr> <tr> <td>Réalisation</td> <td>:</td> <td> <textarea name="realisation" value="<?php echo $tableau[9]; ?>" cols=70 rows=3></textarea> </td> </tr> <tr> <td>Impact</td> <td>:</td> <td> <textarea name="impact" cols=70 rows=3 value="<?php echo $tableau[10]; ?>"></textarea> </td> </tr> <tr> <td>Suite éventuelle<br></td> <td>:</td> <td> <textarea name="suite" cols=70 rows=3 value="<?php echo $tableau[11];?>" ></textarea> </td> </tr> <tr> <td>Observations</td> <td>:</td> <td><textarea name="observation" cols=70 rows=3 value="<?php echo $tableau[12]; ?>"></textarea> </td> </tr> <tr> <td><strong>VERSION MALAGASY</strong></td> <td> </td> <td> </td> </tr> <tr> <td>Fampatsiahivana tetikasa</td> <td>:</td> <td><textarea name="tsiahy" cols=70 rows=3 value="<?php echo $tableau[13]; ?>"></textarea> </td> </tr> <tr> <td>Zava-bita</td> <td>:</td> <td><textarea name="zava_bita" cols=70 rows=3 value="<?php echo $tableau[14]; ?>"></textarea> </td> </tr> <tr> <td>Fiantraikany<br></td> <td>:</td> <td><textarea name="traika" cols=70 rows=3 value="<?php echo $tableau[15]; ?>"></textarea> </td> </tr> <tr> <td><font size="3">Ny mety ho tohin ny asa sy ny fanatsarana azy</font><br></td> <td>:</td> <td><textarea name="tohiny" cols=70 rows=3 value="<?php echo $tableau[16]; ?>"></textarea> </td> </tr> <tr> <td>Fanamarihana <br></td> <td>:</td> <td> <textarea name="marika" cols=70 rows=3 value="<?php echo $tableau[17]; ?>"></textarea> </td> </tr> </table> <center><input type="Submit" value="Soumettre la modification"> </center> </form> <? } ?> </body> </html>
L’envoi du mis à jour et update modification2.php c’est ici que je commence à être bloqué
La page de suppression qui reste, aussi je ne connais rien à mettre là bas. Que pourrais-je faire. Aide –moi
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <html> <head> <title>Index du champ d'ajout</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <? // Utilisation de la fonction include pour le paramètre de connexion include('connexion.inc.php') ; // connexion au serveur mysql mysql_select_db("real_",$connexion); // Selection de la base $db = mysql_select_db( "real_" ) ; //récupération des valeurs des champs: $auteur=$_POST['auteur']; $date=$_POST['date']; $titre=$_POST['titre']; $departement=$_POST['departement']; $programme_projet=$_POST['programme_projet']; $axe_strategique=$_POST['axe_strategique']; $rappel=$_POST['rappel']; $realisation=$_POST['realisation']; $impact=$_POST['impact']; $suite=$_POST['suite']; $observation=$_POST['observation']; $tsiahy=$_POST['tsiahy']; $zava_bita=$_POST['zava_bita']; $traika=$_POST['traika']; $tohiny=$_POST['tohiny']; $marika=$_POST['marika']; //création de la requête SQL: $sql = "UPDATE real SET auteur = '$auteur', date = '$date', titre = '$titre', departement = '$departement', programme_projet = '$programme_projet', axe_strategique = '$axe_strategique', rappel = '$rappel', realisation = '$realisation', impact = '$impact', suite = '$suite', observation = '$observation', tsiahy = '$tsiahy', zava_bita = '$zava_bita', traika = '$traika', tohiny = '$tohiny', marika = '$marika', WHERE id = '$id' " ; //exécution de la requête SQL: $requete = mysql_query($sql, $connexion) or die( mysql_error() ) ; //affichage des résultats, pour savoir si la modification a marchée: if($requete) { echo("La modification à été correctement effectuée") ; } else { echo("La modification à échouée") ; } ?> </body> </html>
Merci à vous.
Partager