Bonsoir,

Je reviens vers vous une fois de plus parce qu'une fois de plus je suis bloque

J'ai un fichier php qui affiche le contenu d'une table de ma base de donnee, jusque la tout se passe bien.
En dessous, j'ai un formulaire qui permet de renseigner les champs pour la base de donnee et quatre boutons (ajouter, editer, supprimer et reset). Et jusque la tout va bien aussi.

Les probleme arrive lorsque je teste tout ca. Je remplis donc tous mes champs et clique sur ajouter... et la, je recois le message d'erreur suivant:
"Error in the SQL request: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined"

Je comprends bien le message d'erreur mais la ou je ne comprends pas, c'est pourquoi mon nombre de parametre est non valide ou un parametre non defini. J'ai repris le code plusieurs fois et je ne vois pas d'ou ca peut venir.

Est-ce que vous avez deja eu ce genre d'erreur?

Voila mon code si vous voulez y jeter un oeil.

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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<?php
header("Content-Type: text/html; charset=iso-8859-1");
// Parametres de connexion à la base de données
$dbhost='xxxxx'; // adresse
$dblogin='xxxxxx'; // login
$dbpassword='x'; // mot de passe
$dbname='xxxxx'; // nom de la base
 
$connexion = false;
 
//connexion a la base de donnees
try {
	$bdd = new PDO('mysql:host='.$dbhost.';dbname='.$dbname, $dblogin, $dbpassword);
	//echo 'Database connection succeeded.';
	$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // permet de recuperer tous les type d'erreurs
	$connexion = true;
}
catch (PDOException $erreur) {
	echo '*** Error establishing a database connection: ' . $erreur->getMessage();
}
 
if ($connexion){
	//Récupération des données
	$req = $bdd->prepare('SELECT * FROM flights');
	$req->execute();
	?>
 
	<p>
	<form action="" method="post">
	<table BORDER=0 CELLSPACING=0>
	<CAPTION>Your flights :</CAPTION>
	<tr BGCOLOR="#C0C0C0">
	<th ALIGN="center" WIDTH=10></th>
	<th ALIGN="center" WIDTH=10>Id</th>
	<th ALIGN="center" WIDTH=60>Date ad</th>
	<th ALIGN="center" WIDTH=80>From</th>
	<th ALIGN="center" WIDTH=80>To</th>
	<th ALIGN="center" WIDTH=60>Price</th>
	<!--<th ALIGN="center" WIDTH=40>Nb. Seats</th>-->
	<th ALIGN="center" WIDTH=60>Date min</th>
	<th ALIGN="center" WIDTH=60>Date max</th>
	<!--<th ALIGN="center" WIDTH=80>Aircraft</th>-->
	<th ALIGN="center" WIDTH=80>Company</th>
	<th ALIGN="center" WIDTH=80>Company_id</th>
	<th ALIGN="center" WIDTH=80>Contact_email</th>
	</tr>
 
	<?php
	// On affiche chaque entree une à une
	while ($donnees = $req->fetch())
	{
	// en ajoutant [] apres la valeur dans l'attribut name, on recuperera en PHP un tableaux contenant les valeurs des checkbox qui auront ete cochees.
	?>
 
	<tr>
	<td ALIGN="center"><input type="checkbox" name="selection[]" value="<?php echo $donnees['Offer_id']; ?>" /></td>
	<td ALIGN="center"><?php echo $donnees['Offer_id']; ?></td>
	<td ALIGN="center"><?php echo $donnees['Datead']; ?></td>
	<td ALIGN="center"><?php echo $donnees['From']; ?></td>
	<td ALIGN="center"><?php echo $donnees['To']; ?></td>
	<td ALIGN="center"><?php echo $donnees['Price']; ?></td>
	<!--<td ALIGN="center"><?php echo $donnees['Seats']; ?></td>-->
	<td ALIGN="center"><?php echo $donnees['Datemin']; ?></td>
	<td ALIGN="center"><?php echo $donnees['Datemax']; ?></td>
	<!--<td ALIGN="center"><?php echo $donnees['Aircraft']; ?></td>-->
	<td ALIGN="center"><?php echo $donnees['Company']; ?></td>
	<td ALIGN="center"><?php echo $donnees['Company_id']; ?></td>
	<td ALIGN="center"><?php echo $donnees['Contact_email']; ?></td>
	</tr>
 
	<?php
	}
	?>
 
	</table>
	</p>
 
	<?php
	$req->closeCursor(); // Termine le traitement de la requête
 
	//session_start();
	if (!isset($_SESSION['reponse_client'])) {
	  $_SESSION['reponse_client'] = ''; // utilisation d'une variable session pour enregistrer les etats precedents
	}
 
	$formulaire_actif = true;
 
	function verification($string) {
		return mysql_real_escape_string(trim($string)); // trim : delete white spaces after & before text
	}
 
	// Correspondance entre les champs du formulaire et ceux de la base de donnees
	$champsLiens = array('datead'=>'Datead', 'from'=>'From', 'to'=>'To', 'price'=>'Price','seats'=>'Seats','datemin'=>'Datemin', 'datemax'=>'Datemax','aircraft'=>'Aircraft','company'=>'Company','company_id'=>'Company_id','contact_email'=>'Contact_email');
 
 
	$champsListeVerif = array_fill_keys(array_keys($champsLiens),''); // donnees
	$champsListe = array_keys($champsListeVerif);
	$champs_modifies = array(); // liste des champs modifies
	$champs_invalide = array(); // liste des champs invalides
	$err = false;
 
	if(isset($_POST['envoi'])) // bouton ajouter
	{
		foreach ($champsListe as $champs) { // verification des champs un par un
			if (isset($_POST[$champs]))
			{
				$champsListeVerif[$champs] = verification($_POST[$champs]);
				if (empty($champsListeVerif[$champs])){
					$champs_invalide[] = $champs; // enregistrement des champs vides
					$err = true;
				}
			}
		}
		unset($champs); // break the reference with the last element
 
		if ($err){ // en cas d'erreur
			$formulaire_actif = true; // pour reafficher le formulaire
			if (count($champs_invalide)==1){
				$_SESSION['reponse_client'] = 'Field '.$champs_invalide[0].' is missing.';
			} else {
				$_SESSION['reponse_client'] = 'Fields '.implode(', ',$champs_invalide).' are missing.';
			}
		} else {
			try {// insertion en base
				$req = $bdd->prepare('INSERT INTO flights(Datead, From, To, Price, Seats, Datemin, Datemax, Aircraft, Company, Company_id, Contact_email) VALUES(:Datead, :From, :To, :Price, :Seats, :Datemin, :Datemax, :Aircraft, :Company, :Company_id, :Contact_email)');
				$req->execute($champsListeVerif);
				$req->closeCursor(); // Termine le traitement de la requete
 
				$formulaire_actif = false; // pour ne pas reafficher le formulaire
				$_SESSION['reponse_client'] = 'A new flight offer (id:'.$bdd->lastInsertId().') has been registered in the database.'; // lastInsertId peut renvoyer l'Id d'une autre table, mais cas peu probable.			
 
			}
			catch (PDOException $erreur) { // Si il y a une erreur
				//echo '*** Error in the SQL request: '. $erreur->getMessage();
				$formulaire_actif = true; // pour reafficher le formulaire
				$_SESSION['reponse_client'] = 'Error in the SQL request: '. $erreur->getMessage();	
			}			
		}
		unset($_POST['envoi']);
	}
 
	if(isset($_POST['modification']))  // bouton modifier
	{
		$formulaire_actif = false;	
		if(isset($_POST['selection']))
		{
			$message = array();
			foreach ($champsListe as $champs) { // verification des champs un par un
				if (isset($_POST[$champs])){
					$champsListeVerif[$champs] = verification($_POST[$champs]);
					if (!empty($champsListeVerif[$champs])){
						$champs_modifies[$champs] = $champsListeVerif[$champs]; // conservation des champs renseignes
					}
				}
			}
			unset($champs); // break the reference with the last element
			$_SESSION['reponse_client'] = '';
			if(count($champs_modifies)!=0){
				foreach($_POST['selection'] as $chkbx){
					// modification de la base
					$tmp = array();
					foreach (array_keys($champs_modifies) as $nomChamps) { // creation de la requete preparee avec les elements uniquement renseignes
						$tmp[] = $champsLiens[$nomChamps].'= :'.$nomChamps;
					}
					unset($nomChamps);
					try {// insertion en base
						$req = $bdd->prepare('UPDATE flights SET '.implode(', ',$tmp).' WHERE Offer_id ='.$chkbx);
						$req->execute($champs_modifies);
						$req->closeCursor(); // Termine le traitement de la requête
 
						$formulaire_actif = false; // pour ne pas réafficher le formulaire
						$message[] = $chkbx;
					}
					catch (PDOException $erreur) { // Si il y a une erreur
						//echo '*** Error in the SQL request: '. $erreur->getMessage();
						$formulaire_actif = true; // pour reafficher le formulaire
						$_SESSION['reponse_client'] = 'Error in the SQL request: '. $erreur->getMessage();
					}
				}
				if (count($message)==1){
					$_SESSION['reponse_client'] .= 'Selection '.$message[0].' has been modified.';
				} else {
					$_SESSION['reponse_client'] .= 'Selections '.implode(', ',$message).' have been modified.';
				}	
			} else {
				$_SESSION['reponse_client'] = 'At least one field must be changed!';
			}
		} else {
			$_SESSION['reponse_client'] = 'At least one selection is required!';	
		}
 
		unset($_POST['modification']);
	}
 
	if(isset($_POST['suppression'])) // bouton supprimer
	{
		$formulaire_actif = false;	
		if(isset($_POST['selection']))
		{
			$message = array();
			foreach($_POST['selection'] as $chkbx){
				try {// insertion en base
					$req = $bdd->prepare('DELETE FROM flights WHERE Offer_id ='.$chkbx);
					$req->execute();
					$req->closeCursor(); // Termine le traitement de la requête
 
					$formulaire_actif = false; // pour ne pas réafficher le formulaire
					$message[] = $chkbx;
				}
				catch (PDOException $erreur) { // Si il y a une erreur
					$formulaire_actif = true; // pour reafficher le formulaire
					$_SESSION['reponse_client'] = 'Error in the SQL request: '. $erreur->getMessage();
				}
			}
			if (count($message)==1){
				$_SESSION['reponse_client'] .= 'Selection '.$message[0].' has been deleted.';
			} else {
				$_SESSION['reponse_client'] .= 'Selections '.implode(', ',$message).' have been deleted.';
			}
		} else {
			$_SESSION['reponse_client'] = 'At least one selection is required!';	
		}
 
		unset($_POST['suppression']);
	}
	?>
 
	<p style="color:#A60000; font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:bold"><?php echo $_SESSION['reponse_client'];?></p>
	<?php
	if ($formulaire_actif)
	{
	unset($_SESSION['reponse_client']); // detruit la variable de session pour eviter l'affichage au rechargement de la page
	?>
	<p>
	<legend style="color:#C0C0C0;font-size:18px; font-weight:bold">Add/Modify/Delete a flight offer:</legend>
	<!--<div>
	<label for="nom">Offer id:</label>
	<input type="text" name="Offer_id" value="<?php echo $champsListeVerif['offer_id'];?>"/>
	</div>-->
	<div>
	<label for="adresse">Today's date:</label>
	<input type="text" name="Datead" value="<?php echo $champsListeVerif['datead'];?>"/>
	</div>
	<div>
	<label for="adresse">From:</label>
	<input type="text" name="From" value="<?php echo $champsListeVerif['from'];?>"/>
	</div>
	<div>
	<label for="tel">To:</label>
	<input type="text" name="To" value="<?php echo $champsListeVerif['to'];?>"/>
	</div>
	<div>
	<label for="contact">Price:</label>
	<input type="text" name="Price" value="<?php echo $champsListeVerif['price'];?>"/> (Please state the currency)
	</div>
	<div>
	<label for="mail">Number of Seats:</label>
	<input type="text" name="Seats" value="<?php echo $champsListeVerif['seats'];?>"/>
	</div>
	<div>
	<label for="mail">Date min:</label>
	<input type="text" name="Datemin" value="<?php echo $champsListeVerif['datemin'];?>"/>
	</div>
	<div>
	<label for="mail">Date max:</label>
	<input type="text" name="Datemax" value="<?php echo $champsListeVerif['datemax'];?>"/>
	</div>
	<div>
	<label for="mail">Aircraft:</label>
	<input type="text" name="Aircraft" value="<?php echo $champsListeVerif['aircraft'];?>"/>
	</div>
	<div>
	<label for="mail">Company:</label>
	<input type="text" name="Company" value="<?php echo $champsListeVerif['company'];?>"/>
	</div>
	<div>
	<label for="mail">Company_id:</label>
	<input type="text" name="Company_id" value="<?php echo $champsListeVerif['company_id'];?>"/>
	</div>
	<div>
	<label for="mail">Contact_email:</label>
	<input type="text" name="Contact_email" value="<?php echo $champsListeVerif['contact_email'];?>"/>
	</div>
	<div>
	<input type="submit" name="envoi" value="Add" class="btn btn-primary" />
	<input type="submit" name="modification" value="Modify" class="btn btn-primary" />
	<input type="submit" name="suppression" value="Delete" class="btn btn-primary" />
	<input type="reset" value="Reset" class="btn btn-primary" />
	</div>
	</p>
	</form>
	<?php
	}
	else{
	header ("location: http://easystk.com/index.php/en/overseeing/customers");
	exit;
	}
} else {
	echo 'This service is temporarily unavailable. Please apologize for the inconvenience.';
}
?>
Merci pour votre aide et bonne soiree