Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 06/02/2011, 12h05   #1
Invité régulier
 
lucas bonomi
Inscription : décembre 2010
Messages : 86
Détails du profil
Informations personnelles :
Nom : lucas bonomi
Âge : 21
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations forums :
Inscription : décembre 2010
Messages : 86
Points : 7
Points : 7
Envoyer un message via MSN à lukyVJ Envoyer un message via Skype™ à lukyVJ
Par défaut Souci de Mise à Jour Base de données

Bonjour à tous, je dois faire la page d'un site qui sera une page dite "de Mises à jours", j'ai rédigé mes 3 requetes differentes (inserer, modifier, supprimer)
mais à ma grande surprise, malgrès que j'appuie sur le boutton supprimer, ça n'exécute que la première requête (inserer)... je ne sais pas d'ou viens cette erreur.. merci à celui ou celle qui pourra m'aiguiller ! Merci.

Bien à vous
Luky.

Mon code
Code :
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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
if(isset($_POST['txtTitre'])){ 
 
	$query = " INSERT INTO  films (id ,titre ,description ,image ,link ,link2 ,allocine ,Date_add ,people ,language ,genre ,qualité)
				VALUES (   NULL,
				'".mysql_real_escape_string($_POST["txtTitre"])."',  
				'".mysql_real_escape_string($_POST["txtDescription"])."',
				'".mysql_real_escape_string($_POST["txtImage"])."', 
				'".mysql_real_escape_string($_POST["txtMegaupload"])."', 
				'".mysql_real_escape_string($_POST["txtMegavideo"])."',
				'".mysql_real_escape_string($_POST["txtAllocine"])."',
				 NOW(),  
				'".mysql_real_escape_string($_POST["txtPeople"])."',
				'".mysql_real_escape_string($_POST["cboLanguage"])."',
				'".mysql_real_escape_string($_POST["rbtnGenre"])."',
					'".mysql_real_escape_string($_POST["rbtnQual"])."');";
 
 
if (isSet ($_POST['modifier']))
$requete = "UPDATE films SET titre=$txtTitre,"
."description='$txtDescription',image='$txtImage', link='$txtMegaupload',"
."link2='$txtMegavideo', allocine='$txtAllocine', people='$txtPeople',"
."languages='$cboLanguage', genre='$rbtnGenre', qualité='$rbtnQual'";
 
if (isSet($_POST['detruire']))
$requete = "DELETE FROM films WHERE titre='$titre'";
 
 
if (isSet ($_POST['inserer']))
echo "Insertion du film $titre ok .";
else if (isSet ($_POST['modifer']))
echo "Modifications du film $titre ok .";
else if (isSet ($_POST['detruire']))
echo "Destruction du film $titre ok.";
 
 
 
 
 //echo $query;
mysql_connect('...','...','...') or die(mysql_error());
mysql_select_db('...') or die(mysql_error());
 
mysql_query($query) 
	or die(mysql_error());  
	@mysql_close($connection); 	
	echo "La Requête '$requete' a été exécutée \n";
}
?>
 
</div>
<div class="nav_bo"><h3> <a href="BO_dep.php">Ajouter un film</a> | <a href="BO_bandanonce.php">Ajouter une bande annonce</a> |<a href="BO_news.php">Ajouter une actu</a>  </h3> </div> 
 
<titre><h1>Ajouter un Film</h1></titre>
 
 <div class="formulaire_fl">
<form method="post" action="#" name="insertForm"  enctype="multipart/form-data">  
<table>  
    <tfoot> 
        <tr> 
            <th colspan="5" align="right" class="tblFooters"> 
 
            </th> 
        </tr> 
    </tfoot> 
    <tbody> 
        <tr> 
            <td  align="center"> 
                Titre              
            </td> 		 
			<td> 
                <input type="text" name="txtTitre" id="txtTitre" value="" size="40" MAXLENGTH=255 class="textfield" id="field_2_3" /> 
            </td> 
        </tr> 
        <tr> 
            <td  align="center"> 
              Description <br /> R&eacute;sum&eacute; / synospis 
            </td> 
			<td> 
                <textarea name="txtDescription" id="txtDescription" rows="7" cols="40" dir="ltr" id="field_3_3" tabindex="7" ></textarea>             
            </td> 
        </tr> 
        <tr> 
            <td  align="center"> 
               Lien Image              
            </td>                   
			<td> 
				<input type="text" name="txtImage" id="txtImage" value="" size="40" MAXLENGTH=255 class="textfield" tabindex="10" id="field_4_3"/> 
			</td> 
        </tr> 
		<tr> 
            <td  align="center"> 
              Lien MEGAUPLOAD 
            </td> 
			<td> 
				<input type="text" name="txtMegaupload" id="txtMegaupload" value="" size="40" MAXLENGTH=255 class="textfield" tabindex="13" id="field_5_3" /> 
			</td> 
        </tr> 
        <tr> 
            <td  align="center"> 
              Lien MEGAVIDEO
            </td>   
			<td>  
                <input type="text" name="txtMegavideo" id="txtMegavideo" value="" size="40" MAXLENGTH=255 class="textfield"  tabindex="16"  id="field_6_3" /> 
            </td> 
        </tr> 
        <tr>
            <td  align="center"> 
             Lien Allociné
            </td>   
			<td>  
                <input type="text" name="txtallocine" id="txtallocine" value="" size="40" MAXLENGTH=255 class="textfield"  tabindex="16"  id="field_6_3" /> 
            </td> 
        </tr> 
        <tr> 
            <td  align="center"> 
                Votre Pseudo
            </td> 
			<td> 
                <input type="text" name="txtPeople" id="txtPeople"  value="" size="20"  class="textfield" tabindex="22" id="field_8_3" /> 
            </td> 
        </tr> 
        <tr> 
            <td  align="center">
				language</span>              
            </td>  
			<td> 
				<SELECT name="cboLanguage" id="cboLanguage" size="1">
					<OPTION>VF
					<OPTION>VO
					<OPTION>VOST 
				</SELECT>
            </td> 
        </tr> 
        <tr> 
            <td  align="center"> 
				Genre            
            </td> 
			<td> 
			<!--
				<SELECT name="cboGenre" id="cboGenre" size="1">
					<OPTION>COMEDIE
					<OPTION>DRAMES
					<OPTION>HORREUR 
					<OPTION>ACTION 
					<OPTION>HISTOIRE 
					<OPTION>AMOUR 
					<OPTION>ANIMATION 					
				</SELECT>
			-->
				<input type="checkbox" name="rbtnGenre" value="COMEDIE " />COMEDIE
				<input type="checkbox" name="rbtnGenre" value="DRAMES " />DRAMES
				<input type="checkbox" name="rbtnGenre" value="HORREUR " />HORREUR
				<input type="checkbox" name="rbtnGenre" value="ACTION " />ACTION
				<input type="checkbox" name="rbtnGenre" value="HISTOIRE " />HISTOIRE
				<input type="checkbox" name="rbtnGenre" value="ANIMATION " />ANIMATION
                <input type="checkbox" name="rbtnGenre" value="DOCUMENTAIRE " />DOCUMENTAIRE
                 <input type="checkbox" name="rbtnGenre" value="POLICIER " />POLICIER
                <input type="checkbox" name="rbtnGenre" value="SPORTS " />SPORTS
                <input type="checkbox" name="rbtnGenre" value="MUSIQUE " />MUSIQUE
 
			</td> 
		</tr>
        <tr> 
            <td  align="center"> 
				Qualit&eacute;         
            </td> 
			<td> 
			<input type="checkbox" name="rbtnQual" value="HD" />HD
				<input type="checkbox" name="rbtnQual" value="Tres bonne " />Tres bonne
				<input type="checkbox" name="rbtnQual" value="Bonne " />Bonne
				<input type="checkbox" name="rbtnQual" value="Moyenne " />Moyenne
                <input type="checkbox" name="rbtnQual" value="Mauvaise " />Mauvaise
 
			</td> 
		</tr>			
    </tbody></table><br /><br />
     <p><h3><input type="submit" value="Envoyer le film" class="pane-list"  name="inserer"/></p></h3><br>
<br>
 
   <p><input type="submit" value="Modifier le film" name="modifier"></p>
   <p><input type="submit" value="Supprimer le film" name="supprimeer"></p>
</form> 
 </div>
                </div>
 
                    </div>
lukyVJ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/02/2011, 12h26   #2
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Tu n'as pas d'execution pour tes requetes supprimer/modifier.

Par ailleurs, utilise un switch ou un if/elseif plutot que des if successifs.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/02/2011, 12h37   #3
Expert Confirmé
 
Avatar de RunCodePhp
 
Inscription : janvier 2010
Messages : 2 706
Détails du profil
Informations personnelles :
Localisation : Réunion

Informations forums :
Inscription : janvier 2010
Messages : 2 706
Points : 3 274
Points : 3 274
Salut

Il y a des truc qui vont pas à mon sens.

En 1er, on vérifie l'existence de "txtTitre", mais si "txtDescription" ou "txtImage" n'existe pas, ça va bugger.

Puis juste après avoir vérifier "txtTitre", on initialise $query avec un INSERT INTO, or, à ce stade là du déroulement rien ne dit qu'il faille insérer.


Essai plus quelque chose comme :
Code :
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
 
$erreur = FALSE;
//
if (isset($_POST['actionFilm'])) {
 
    if (isset($_POST["txtTitre"], $_POST["txtDescription"]) ... etc ...) {
        // Initialisation des données
        // Vérification des données
        $txtTitre = mysql_real_escape_string($_POST["txtTitre"]);
        ... etc ...
    }
    else {
        $erreur = TRUE;
    }
 
    if ($erreur == FALSE) {
 
        switch ($_POST['actionFilm']) {
        case : 'ajouter' :
            // Requête SQL / traitement pour insérer
        break;
        case : 'modifier' :
            // Requête SQL / traitement pour modifier
        break;
        case : 'supprimer' :
            // Requête SQL / traitement pour supprimer
        break;
        }
 
    }
}
En somme, il faudrait donner le même nom des 3 boutons submit : C'est l'action à réaliser (actionFilm : ajouter ou modifier ou supprimer).

- On vérifie que l'action existe (donc tout le bloc ne se fera QUE dans ce cas là)
- On vérifie l'existence des données à traitées, et nonmrlament on vérifie aussi que leur valuers soient celles attendues (sinon erreur).
- On exécute la requête selon l'action uniquement s'il n'y a pas eu d'erreurs.


Enfin, c'est une idée.
__________________
Win XP | WampServer 2.2d | Apache 2.2.21 | Php 5.3.10 | MySQL 5.5.20
Si debugger, c'est supprimer des bugs, alors programmer ne peut être que les ajouter [Edsger Dijkstra]
RunCodePhp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/02/2011, 21h52   #4
Membre émérite
 
Avatar de vorace
 
Homme
Développeur
Inscription : août 2010
Messages : 586
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Meurthe et Moselle (Lorraine)

Informations professionnelles :
Activité : Développeur

Informations forums :
Inscription : août 2010
Messages : 586
Points : 859
Points : 859
un petit conseil, utilise $_REQUEST['nom_du_submit'] pour savoir quel bouton submit à été cliqué...
vorace est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/02/2011, 11h54   #5
Invité régulier
 
lucas bonomi
Inscription : décembre 2010
Messages : 86
Détails du profil
Informations personnelles :
Nom : lucas bonomi
Âge : 21
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations forums :
Inscription : décembre 2010
Messages : 86
Points : 7
Points : 7
Envoyer un message via MSN à lukyVJ Envoyer un message via Skype™ à lukyVJ
Merci pour votre aide (je teste ça ce soir, je vous en dirais des nouvelles ! )

L
lukyVJ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/02/2011, 13h49   #6
Candidat au titre de Membre du Club
 
Inscription : décembre 2004
Messages : 46
Détails du profil
Informations forums :
Inscription : décembre 2004
Messages : 46
Points : 14
Points : 14
Yep Lucky,

voila ce qu'il en est. J'ai fait ca sans le débugger ni le tester. il peux donc y avois quelques bug qui traine mais bon tu devrais trouver facilement !
creer une nouvelle page avec ce code et test avant d'écraser la tienne !
@+

(Makayel)

Code :
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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
 
<?php
if(isset($_POST['txtTitre'])){ 
 if (isset($_POST["txtTitre"],$_POST["txtDescription"],$_POST["txtImage"],$_POST["txtDescription"],$_POST["txtMegaupload"],$_POST["txtMegavideo"],$_POST["txtAllocine"],$_POST["txtPeople"],$_POST["cboLanguage"],$_POST["rbtnGenre"],$_POST["rbtnQual"]		   )
 
 
$titre=mysql_real_escape_string($_POST["txtTitre"]);
$desc=mysql_real_escape_string($_POST["txtDescription"]);
$img=mysql_real_escape_string($_POST["txtImage"]);
$mu=mysql_real_escape_string($_POST["txtMegaupload"]);
$mv=mysql_real_escape_string($_POST["txtMegavideo"]);
$ac=mysql_real_escape_string($_POST["txtAllocine"]);
$people=mysql_real_escape_string($_POST["txtPeople"]);
$lang=mysql_real_escape_string($_POST["cboLanguage"]);
$genre=mysql_real_escape_string($_POST["rbtnGenre"]);
$qual=mysql_real_escape_string($_POST["rbtnQual"]);
	$query = " INSERT INTO  films (id ,titre ,description ,image ,link ,link2 ,allocine ,Date_add ,people ,language ,genre ,qualité)
				VALUES (   NULL,
				'".$titre."',  
				'".$desc."',
				'".$img."', 
				'".$mu."', 
				'".$mv."',
				'".$ac."',
				 NOW(),  
				'".$people."',
				'".$lang."',
				'".$genre."',
				'".$qual."');";
 
 
if (isSet ($_POST['modifier']))
$requete = "UPDATE films SET 
			titre='".$titre."',
			description='".$desc."',
			image='".$img."', 
			link='".$mu."',
			link2='".$mv."', 
			allocine='".$ac."', 
			people='".$people."',
			languages='".$lang."', 
			genre='".$genre."', 
			qualité='".$qual."'";
 
if (isSet($_POST['supprimer']))
$requete = "DELETE FROM films WHERE titre='".$titre."'";
 
 
if (isSet ($_POST['inserer']))
echo "Insertion du film $titre ok .";
else if (isSet ($_POST['modifier']))
echo "Modifications du film $titre ok .";
else if (isSet ($_POST['supprimer']))
echo "Destruction du film $titre ok.";
 
 
 
 
 //echo $query;
mysql_connect('...','...','...') or die(mysql_error());
mysql_select_db('...') or die(mysql_error());
 
mysql_query($query) 
	or die(mysql_error());  
	@mysql_close($connection); 	
	echo "La Requête '$requete' a été exécutée \n";
}
?>
 
</div>
<div class="nav_bo"><h3> <a href="BO_dep.php">Ajouter un film</a> | <a href="BO_bandanonce.php">Ajouter une bande annonce</a> |<a href="BO_news.php">Ajouter une actu</a>  </h3> </div> 
 
<titre><h1>Ajouter un Film</h1></titre>
 
 <div class="formulaire_fl">
<form method="post" action="#" name="insertForm"  enctype="multipart/form-data">  
<table>  
    <tfoot> 
        <tr> 
            <th colspan="5" align="right" class="tblFooters"> 
 
            </th> 
        </tr> 
    </tfoot> 
    <tbody> 
        <tr> 
            <td  align="center"> 
                Titre              
            </td> 		 
			<td> 
                <input type="text" name="txtTitre" id="txtTitre" value="" size="40" MAXLENGTH=255 class="textfield" id="field_2_3" /> 
            </td> 
        </tr> 
        <tr> 
            <td  align="center"> 
              Description <br /> R&eacute;sum&eacute; / synospis 
            </td> 
			<td> 
                <textarea name="txtDescription" id="txtDescription" rows="7" cols="40" dir="ltr" id="field_3_3" tabindex="7" ></textarea>             
            </td> 
        </tr> 
        <tr> 
            <td  align="center"> 
               Lien Image              
            </td>                   
			<td> 
				<input type="text" name="txtImage" id="txtImage" value="" size="40" MAXLENGTH=255 class="textfield" tabindex="10" id="field_4_3"/> 
			</td> 
        </tr> 
		<tr> 
            <td  align="center"> 
              Lien MEGAUPLOAD 
            </td> 
			<td> 
				<input type="text" name="txtMegaupload" id="txtMegaupload" value="" size="40" MAXLENGTH=255 class="textfield" tabindex="13" id="field_5_3" /> 
			</td> 
        </tr> 
        <tr> 
            <td  align="center"> 
              Lien MEGAVIDEO
            </td>   
			<td>  
                <input type="text" name="txtMegavideo" id="txtMegavideo" value="" size="40" MAXLENGTH=255 class="textfield"  tabindex="16"  id="field_6_3" /> 
            </td> 
        </tr> 
        <tr>
            <td  align="center"> 
             Lien Allociné
            </td>   
			<td>  
                <input type="text" name="txtallocine" id="txtallocine" value="" size="40" MAXLENGTH=255 class="textfield"  tabindex="16"  id="field_6_3" /> 
            </td> 
        </tr> 
        <tr> 
            <td  align="center"> 
                Votre Pseudo
            </td> 
			<td> 
                <input type="text" name="txtPeople" id="txtPeople"  value="" size="20"  class="textfield" tabindex="22" id="field_8_3" /> 
            </td> 
        </tr> 
        <tr> 
            <td  align="center">
				language</span>              
            </td>  
			<td> 
				<SELECT name="cboLanguage" id="cboLanguage" size="1">
					<OPTION>VF
					<OPTION>VO
					<OPTION>VOST 
				</SELECT>
            </td> 
        </tr> 
        <tr> 
            <td  align="center"> 
				Genre            
            </td> 
			<td> 
			<!--
				<SELECT name="cboGenre" id="cboGenre" size="1">
					<OPTION>COMEDIE
					<OPTION>DRAMES
					<OPTION>HORREUR 
					<OPTION>ACTION 
					<OPTION>HISTOIRE 
					<OPTION>AMOUR 
					<OPTION>ANIMATION 					
				</SELECT>
			-->
				<input type="checkbox" name="rbtnGenre" value="COMEDIE " />COMEDIE
				<input type="checkbox" name="rbtnGenre" value="DRAMES " />DRAMES
				<input type="checkbox" name="rbtnGenre" value="HORREUR " />HORREUR
				<input type="checkbox" name="rbtnGenre" value="ACTION " />ACTION
				<input type="checkbox" name="rbtnGenre" value="HISTOIRE " />HISTOIRE
				<input type="checkbox" name="rbtnGenre" value="ANIMATION " />ANIMATION
                <input type="checkbox" name="rbtnGenre" value="DOCUMENTAIRE " />DOCUMENTAIRE
                 <input type="checkbox" name="rbtnGenre" value="POLICIER " />POLICIER
                <input type="checkbox" name="rbtnGenre" value="SPORTS " />SPORTS
                <input type="checkbox" name="rbtnGenre" value="MUSIQUE " />MUSIQUE
 
			</td> 
		</tr>
        <tr> 
            <td  align="center"> 
				Qualit&eacute;         
            </td> 
			<td> 
			<input type="checkbox" name="rbtnQual" value="HD" />HD
				<input type="checkbox" name="rbtnQual" value="Tres bonne " />Tres bonne
				<input type="checkbox" name="rbtnQual" value="Bonne " />Bonne
				<input type="checkbox" name="rbtnQual" value="Moyenne " />Moyenne
                <input type="checkbox" name="rbtnQual" value="Mauvaise " />Mauvaise
 
			</td> 
		</tr>			
    </tbody></table><br /><br />
     <p><h3><input type="submit" value="Envoyer le film" class="pane-list"  name="inserer"/></p></h3><br>
<br>
 
   <p><input type="submit" value="Modifier le film" name="modifier"></p>
   <p><input type="submit" value="Supprimer le film" name="supprimer"></p>
</form> 
 </div>
                </div>
 
                    </div>
mictif est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/02/2011, 14h05   #7
Invité régulier
 
lucas bonomi
Inscription : décembre 2010
Messages : 86
Détails du profil
Informations personnelles :
Nom : lucas bonomi
Âge : 21
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations forums :
Inscription : décembre 2010
Messages : 86
Points : 7
Points : 7
Envoyer un message via MSN à lukyVJ Envoyer un message via Skype™ à lukyVJ
Thanks le MAKA

à bientôt.
lukyVJ est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 08h41.


 
 
 
 
Partenaires

Hébergement Web