Bonjour,
Tout d'abord je tien a préciser que je ne fait pas partie des codeurs en herbe qui cours poster leurs problème dés les premiers blocages... Ce qui m'a valu probablement pas plus de 2 sujets de demande d'aides sur internet dans la bonne 10 ene d'années de codage php a plein temps.

Cette fois j'en suis arrivé a ne plus avoir de cheveux sur la tête ... 3 jours de blocage.

Mon problème :

Je tente de passer tout simplement le contenu d'un formulaire vers ma base MySQL mais celle-ci me boude.
En effet j'utilise un modèle qui fonctionne tout a fait pour enregistrer des catégories (site E-commerce, donc catégorie de produits).

Voila le modèle (//commenté):



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
 
<?php
 
// Ici j'ajoute une catégorie a la table 'categories' ----------------
// Connection mysql
try
{
	$bdd = new PDO('mysql:host=*HOST;dbname=*DATABN', '*USER', '*MDP');
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
}
 
//Déclaration des variables --
 
//Id 'Auto-increment' par mysql
$id = "";
//Récupération des valeurs du formulaire
$nom =  $_POST["nom"];
$souscat =  $_POST["souscat"];
$color = $_POST["color"];
$color2 = $_POST["color2"];
$type = $_POST["type"];
 
// Si case OPEN coché dans le formulaire : 1, Sinon : 0.
$open = "";
$case = $_POST["open"];
if(!empty($case)){
	$open = "1";}
else{
	$open = "0";}
 
 
 
 
 
// Je prépare et j'envois l'entrée a mysql --
 
$req = $bdd->prepare('INSERT INTO categorie(id, nom, souscat, color, color2, type, open) VALUES(:id, :nom, :souscat, :color, :color2, :type, :open)');
$req->execute(array(
	'id' => $id,				
	'nom' => $nom,
	'souscat' => $souscat,
	'color' => $color,
	'color2' => $color2,
	'type' => $type,
	'open' => $open
	));
 
echo 'La categorie a bien ete ajoute !';
 
?>
Ce script fonctionne ! les catégories s'ajoutent pas de souci.

Mais lorsque je me suis attaqué a l'ajout de produits sur le même modèle, problème...

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
 
 
<?php
 
try
{
	$bdd = new PDO('mysql:host=*HOST;dbname=*DATABN', '*USER', '*MDP');
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
}
 
// déclaration des variables
$id = "";
 
 
if (isset($_POST['categorie']))
{
$categorie =  $_POST["categorie"];
}
 
if (isset($_POST['nom']))
{
$nom =  $_POST["nom"];
}
 
//Je précise que j'ai placer une case a cocher a coté des champs comme ceux si dessous, simplement pour préciser si l'utilisateur veux laisser le champ NULL / Vide, ce qui remplace la valeur de la variable par 'anull'.
Dans le champs ci dessous: Si la case nommé '1null' a coté du champ 'constructeur' est coché : $constructeur = 'anull'.
 
 
$constructeur = $_POST["constructeur"];
	if(!empty($_POST["1null"])){
		$constructeur = "anull";}
 
 
 
$prixbarre = $_POST["prixbarre"];
	if(!empty($_POST["2null"])){
		$prixbarre = "anull";}
 
if (isset($_POST['prixht']))
{
$prixht = $_POST["prixht"];
}
 
 
if (isset($_POST['prix']))
{
$prix = $_POST["prix"];
}
 
if (isset($_POST['poid']))
{
$poid = $_POST["poid"];
}
 
if (isset($_POST['stock']))
{
$stock = $_POST["stock"];
}
 
 
$o1 = $_POST["1"];
	if(!empty($_POST["1null"])){
		$o1 = "anull";}
 
 
$o2 = $_POST["2"];
	if(!empty($_POST["2null"])){
		$o2 = "anull";}
 
 
$o3 = $_POST["3"];
	if(!empty($_POST["3null"])){
		$o3 = "anull";}
 
$o4 = $_POST["4"];
	if(!empty($_POST["4null"])){
		$o4 = "anull";}
 
 
$o5 = $_POST["5"];
	if(!empty($_POST["5null"])){
		$o5 = "anull";}
 
 
 
$o6 = $_POST["6"];
	if(!empty($_POST["6null"])){
		$o6 = "anull";}
 
 
 
$o7 = $_POST["7"];
	if(!empty($_POST["7null"])){
		$o7 = "anull";}
 
 
 
$o8 = $_POST["8"];
	if(!empty($_POST["8null"])){
		$o8 = "anull";}
 
 
 
$o9 = $_POST["9"];
	if(!empty($_POST["9null"])){
		$o9 = "anull";}
 
 
 
$o10 = $_POST["10"];
	if(!empty($_POST["10null"])){
		$o10 = "anull";}
 
 
 
$o11 = $_POST["11"];
	if(!empty($_POST["11null"])){
		$o11 = "anull";}
 
 
 
$o12 = $_POST["12"];
	if(!empty($_POST["12null"])){
		$o12 = "anull";}
 
 
 
$o13 = $_POST["13"];
	if(!empty($_POST["13null"])){
		$o13 = "anull";}
 
 
 
$o14 = $_POST["14"];
	if(!empty($_POST["14null"])){
		$o14 = "anull";}
 
 
 
$o15 = $_POST["15"];
	if(!empty($_POST["15null"])){
		$o15 = "anull";}
 
 
$o16 = $_POST["16"];
	if(!empty($_POST["16null"])){
		$o16 = "anull";}
 
 
 
$o17 = $_POST["17"];
	if(!empty($_POST["17null"])){
		$o17 = "anull";}
 
 
 
$o18 = $_POST["18"];
	if(!empty($_POST["18null"])){
		$o18 = "anull";}
 
 
 
$o19 = $_POST["19"];
	if(!empty($_POST["20"])){
		$o19 = "anull";}
 
 
 
$o20 = $_POST["20"];
	if(!empty($_POST["20null"])){
		$o20 = "anull";}
 
 
 
$o21 = $_POST["21"];
	if(!empty($_POST["21null"])){
		$o21 = "anull";}
 
 
 
 
 
$case = $_POST["open"];
if(!empty($case)){
	$open = "1";}
else{
	$open = "0";}
 
 
 
 
 
//Même systeme ... envois mysql de la nouvelle entrée dans la table 'produits'
// certaines variables présente ne sont pas déclarés ici (comme $grande1 $moyenne1 ...) mais le sont dans la partie haute du script qui fonctionne tres bien et retourne des  valeurs)
 
$req = $bdd->prepare('INSERT INTO produits(id, categorie, nom, constructeur, prixbarre, prixht, prixttc, dateajout, poid, stock, img1, img1m, img1s, img2, img2m, img2s, img3, img3m, img3s, img4, img4m, img4s, img5, img5m, img5s, img6, img6m, img6s, img7, img7m, img7s, img8, img8m, img8s, img9, img9m, img9s, img10, img10m, img10s, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14, o15, o16, o17, o18, o19, o20, o21, open) VALUES(:id, :categorie, :nom, :constructeur, :prixbarre, :prixht, :prixttc, :dateajout, :poid, :stock, :img1, :img1m, :img1s, :img2, :img2m, :img2s, :img3, :img3m, :img3s, :img4, :img4m, :img4s, :img5, :img5m, :img5s, :img6, :img6m, :img6s, :img7, :img7m, :img7s, :img8, :img8m, :img8s, :img9, :img9m, :img9s, :img10, :img10m, :img10s, :o1, :o2, :o3, :o4, :o5, :o6, :o7, :o8, :o9, :o10, :o11, :o12, :o13, :o14, :o15, :o16, :o17, :o18, :o19, :o20, :o21, :open)');
$req->execute(array(
	'id' => $id,				
	'categorie' => $categorie,
	'nom' => $nom,
	'constructeur' => $constructeur,
	'prixbarre' => $prixbarre,
	'prixht' => $prixht,
	'prixttc' => $prix,
	'dateajout' => $dateajout,
	'poid' => $poid,
	'stock' => $stock,
	'img1' => $grande1,
	'img1m' => $moyenne1,
	'img1s' => $petite1,
	'img2' => $grande2,
	'img2m' => $moyenne2,
	'img2s' => $petite2,
	'img3' => $grande3,
	'img3m' => $moyenne3,
	'img3s' => $petite3,
	'img4' => $grande4,
	'img4m' => $moyenne4,
	'img4s' => $petite4,
	'img5' => $grande5,
	'img5m' => $moyenne5,
	'img5s' => $petite5,
	'img6' => $grande6,
	'img6m' => $moyenne6,
	'img6s' => $petite6,
	'img7' => $grande7,
	'img7m' => $moyenne7,
	'img7s' => $petite7,
	'img8' => $grande8,
	'img8m' => $moyenne8,
	'img8s' => $petite8,
	'img9' => $grande9,
	'img9m' => $moyenne9,
	'img9s' => $petite9,
	'img10' => $grande10,
	'img10m' => $moyenne10,
	'img10s' => $petite10,
	'o1' => $o1,
	'o2' => $o2,
	'o3' => $o3,
	'o4' => $o4,
	'o5' => $o5,
	'o6' => $o6,
	'o7' => $o7,
	'o8' => $o8,
	'o9' => $o9,
	'o10' => $o10,
	'o11' => $o11,
	'o12' => $o12,
	'o13' => $o13,
	'o14' => $o14,
	'o15' => $o15,
	'o16' => $o16,
	'o17' => $o17,
	'o18' => $o18,
	'o19' => $o19,
	'o20' => $o20,
	'o21' => $o21,
	'open' => $open
	));
 
 
echo 'Le produit a bien ete ajoute !';
 
?>
J'envois, et j'obtiens le 'Le produit a bien ete ajoute !'
seulement en consultant phpmyadmin j'ai aucunes entrée dans la table 'produits' !

Aucune erreur mais pas d'entrée ... j'ai verifié pendant 3 jour la syntaxe, le respect des nom dans la requête, l'ordre... tout !

Lorsque j'ai réduit ma table a 3 champs (id, categorie, nom, constructeur) ça marche ! mais si j'en rajoute 1 (prixbarre, par exemple) ça ne refonctionne plus... puis lorsque je refait la manipulation de repasser a 4 champs, ça marche ! assez aléatoirement...

j'ai retourné le problème dans tout les sens ça ressemble a rien que je connaisse.

le premier script, plus cour, fonctionne a 100% tout le temps !

Précisions :
Je suis chez OVH
J'utilise php5 (par l'extension .php5 chez OVH)

Voila la table produit :

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
 
CREATE TABLE IF NOT EXISTS `produits` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `categorie` text NOT NULL,
  `nom` text NOT NULL,
  `constructeur` text NOT NULL,
  `prixbarre` text NOT NULL,
  `prixht` text NOT NULL,
  `prixttc` text NOT NULL,
  `dateajout` text NOT NULL,
  `poid` text NOT NULL,
  `stock` text NOT NULL,
  `img1` text NOT NULL,
  `img1m` text NOT NULL,
  `img1s` text NOT NULL,
  `img2` text NOT NULL,
  `img2m` text NOT NULL,
  `img2s` text NOT NULL,
  `img3` text NOT NULL,
  `img3m` text NOT NULL,
  `img3s` text NOT NULL,
  `img4` text NOT NULL,
  `img4m` text NOT NULL,
  `img4s` text NOT NULL,
  `img5` text NOT NULL,
  `img5m` text NOT NULL,
  `img5s` text NOT NULL,
  `img6` text NOT NULL,
  `img6m` text NOT NULL,
  `img6s` text NOT NULL,
  `img7` text NOT NULL,
  `img7m` text NOT NULL,
  `img7s` text NOT NULL,
  `img8` text NOT NULL,
  `img8m` text NOT NULL,
  `img8s` text NOT NULL,
  `img9` text NOT NULL,
  `img9m` text NOT NULL,
  `img9s` text NOT NULL,
  `img10` text NOT NULL,
  `img10m` text NOT NULL,
  `img10s` text NOT NULL,
  `o1` text NOT NULL,
  `o2` text NOT NULL,
  `o3` text NOT NULL,
  `o4` text NOT NULL,
  `o5` text NOT NULL,
  `o6` text NOT NULL,
  `o7` text NOT NULL,
  `o8` text NOT NULL,
  `o9` text NOT NULL,
  `o10` text NOT NULL,
  `o11` text NOT NULL,
  `o12` text NOT NULL,
  `o13` text NOT NULL,
  `o14` text NOT NULL,
  `o15` text NOT NULL,
  `o16` text NOT NULL,
  `o17` text NOT NULL,
  `o18` text NOT NULL,
  `o19` text NOT NULL,
  `o20` text NOT NULL,
  `o21` text NOT NULL,
  `open` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
J'ai presque tout mis en texte suite a mes essais désespérés mais même avec un réglage approprié des champs rien ne change.

Je remercie ceux qui prendrons le temps de m'aider. je suis conscient du caractère décourageant du problème (vus la taille du sujet je pris pour qu'au moins une personne arrive a tout lire ...).

Bonne journée.