Bonjour à tous voila j'ai un souci cela fait trois jours maintenant que je suis bloqué sur la même page ! En faite le but de ma page est de remplir un premier formulaire, une foi rempli un deuxième apparait juste en dessous dans lequel on saisi également des informations puis pour finir on appui sur le bouton enregistrer qui est censé tout écrire ensuite dans ma base de données. Mais voila j'ai un souci l'instruction s'éxécutant après mon deuxième formulaire n'arrive pas j'ai l'impression à récupérer certaines valeurs du formulaire numéro 1 comme $ligne par exemple. Donc je voulais savoir si quelqu'un pourrais regarder mon code et me dire d'où peut venir le souci et comment le résoudre.

Merci d'avance,

Voila mon code (j'espère qu'il ne sera pas tro long de toute manière tout marche sauf la dernière instruction if, j'ai mi un test le premier marche mai le deuxième avec écrit "Ca marche c kool la" ne saffiche pas donc je pense que ca vien de ma variable $ligne qui est mal récupéré)

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
<html>
 
<head>
 
<script language="JavaScript">
<!--
function total(i)
    {
    var qt=document.forms["form2"].elements["qte_"+arguments[0]].value;
    var pr=document.forms["form2"].elements["prix_"+arguments[0]].value;
    var total=qt*pr;
    document.forms["form2"].elements["tot_"+arguments[0]].value = total;
    }
//-->
</script>
 
<script language="JavaScript">
<!--
function global(nb_ligne)
    {
    var totalglobal=0;
    for (var i=1;i<=arguments[0];i++)
        {
        var totgb= new Number(document.forms["form2"].elements["tot_"+i].value);
        var totalglobal = totalglobal + totgb;
        }
    document.forms["form2"].elements["totglobal"].value = totalglobal;
    }
//-->
</script>
 
<script language="JavaScript">
<!--
function msg(bl,ligne) {
    // pose une question au visiteur
    var total_msg=document.forms["form2"].elements["totglobal"].value;
    if (confirm("Vous allez enregistrer le BL "+arguments[0]+" d'un montant de "+total_msg+" euros !")) {
        document.forms["form2"].elements["rep_msg"].value =0;
        for (var i=1;i<=arguments[1];i++)
        {
        document.forms["form2"].elements["fct_"+i].value = document.forms["form2"].elements["article_"+i].options[document.forms["form2"].elements["article_"+i].selectedIndex].text;
        }
    } else {
        document.forms["form2"].elements["rep_msg"].value =1;
        for (var i=1;i<=arguments[1];i++)
        {
        document.forms["form2"].elements["fct_"+i].value = document.forms["form2"].elements["article_"+i].options[document.forms["form2"].elements["article_"+i].selectedIndex].text;
        }
    }
}
//-->
</script>
 
<script language="JavaScript">
<!--
function prix(ligne) {
document.forms["form2"].elements["prix_"+arguments[0]].value = document.forms["form2"].elements["article_"+arguments[0]].options[document.forms["form2"].elements["article_"+arguments[0]].selectedIndex].value;
document.forms["form2"].elements["fct_"+arguments[0]].value = document.forms["form2"].elements["article_"+arguments[0]].options[document.forms["form2"].elements["article_"+arguments[0]].selectedIndex].text;
--alert(essai);
}
//-->
</script>
 
<script language="JavaScript">
<!--
function recsuit()
    {
    alert (document.forms["form1"].elements["ligne"].value);
    alert (document.forms["form1"].elements["bl"].value);
    alert (document.forms["form1"].elements["comment"].value);
    document.forms["form1"].elements["recsuite"].value = "yes" ;
    }
//-->
</script>
 
<script language="JavaScript">
<!--
function recenreg()
    {
    alert (document.forms["form1"].elements["ligne"].value);
    alert (document.forms["form1"].elements["bl"].value);
    alert (document.forms["form1"].elements["comment"].value);
    document.forms["form2"].elements["recenregist"].value = "yes" ;
 
    }
//-->
</script>
 
<script language="JavaScript"> 
function process_keypress() { 
if (window.event.type == "keypress" & window.event.keyCode == 13) 
alert("touche ENTREE rendue inoperante sur ce programme."); 
return !(window.event.type == "keypress" & window.event.keyCode == 13); 
} 
document.onkeypress = process_keypress; 
</script> 
 
 
</head>
 
<body bgcolor="#006699">
 
 
<?
 
$db = mysql_connect("localhost", "root");
mysql_select_db("consommable",$db);
 
$totalgen=0;
 
echo "<center>";
 
echo "<h2>Reception Consommable</h2><br><br>";
 
echo "<table><form name=\"form1\" method=POST>";
echo "<tr><td><b>Fournisseur : </b></td><td><select name=\"nofour\" tabindex=\"1\">\n";
echo "<option selected>$nofour</option>\n";
$var="select distinct(nom) from fournisseur order by nom";
$var2=mysql_query($var);
while($row=mysql_fetch_row($var2))
        {
        echo "<option>$row[0]</option>\n";
        }
echo "</select></td>";
 
mysql_select_db("inventaire",$db);
 
echo "<blockquote><td><b>Destinataire : </b></td><td><select name=\"magasin\" tabindex=\"2\">
<option selected>$magasin</option>";
$var="select * from magasin order by nummag";
$var2=mysql_query($var);
while($row=mysql_fetch_row($var2))
{
echo "<option>$row[0] $row[1]</option>";
}
echo "<option>Centrale</option>";
echo "</select></td></tr>";
 
mysql_select_db("consommable",$db);
 
echo "<tr><td><b>Date de reception : </b></td><td><input type=\"date\" name=\"date\" tabindex=\"3\" value=$date></td>
<td><b>Numero de BL : </b></td><td><input type=\"text\" name=\"bl\" tabindex=\"4\" value=$bl></td></tr>
<tr><td></td><td>(Format : AAAA-MM-JJ)</td></tr>
<tr><td><b>Nb d'article : </b></td><td><input type=\"text\" name=\"ligne\" tabindex=\"5\" value=$ligne></td>
<td><b>Commentaire : </b></td><td><TEXTAREA NAME=\"comment\" COLS=\"18\" ROWS=\"3\" tabindex=\"6\">$comment</TEXTAREA></td></tr>
</table><br>

<button type=\"Submit\" name=\"submit\" onclick=\"javascript:recsuit()\"><img src=\"../OK.gif\"><b>Suite</b></button>
<input type=hidden name=\"recsuite\" value=no>

<button type=\"Reset\" name=\"reset\" value=\"Reset\" onclik=\"commeuro.php\"><img src=\"../annuler.gif\"><b>Annuler</b></button>
</form>
</center>"; //<input type=\"Submit\" name=\"submit\" value=\"Suite\" tabindex=\"7\">
 
$recsuite=$_POST['recsuite'];
$ligne=$_POST['ligne'];
$bl=$_POST['bl'];
if(($recsuite=="yes" or $recenregist=="yes") and isset($ligne,$bl)) //$submit=="Enregistrer"
{
    echo "<form name=\"form2\" method=POST>";
    echo "<center><table border=2>";
    echo "<tr><td><b>Article</b></td><td><b>Quantite</b></td><td><b>Prix</b></td><td><b>Total</b></td></tr>";
    $i=1;
    while($i<=$ligne)
        {
        // partie qui garde en ecriture les lignes du tableau
        $art[0]="fct_";
        $art[1]=$i;
        $artic=implode($art,"");
        $artic=$$artic;
        $q[0]="qte_";
        $q[1]=$i;
        $qt=implode($q,"");
        $qt=$$qt;
        $p[0]="prix_";
        $p[1]=$i;
        $pr=implode($p,"");
        $pr=$$pr;
        $t[0]="tot_";
        $t[1]=$i;
        $tot=implode($t,"");
        $tot=$$tot;
        //fin affichage donnees saisies
 
        //affichage tableau
        $nofour=$_POST['nofour'];
        echo "<tr><td><select name=\"article_$i\" tabindex=\"7+$i\" onblur=' javascript:prix($i);'>";
        echo "<option selected>$artic</option>\n";
        $var="select distinct(a.codeint),a.libelle,f.prix_actuel from article a,fournisseur f where f.nom='$nofour' and f.codeint=a.codeint order by a.codeint";
        $var2=mysql_query($var);
        while($row=mysql_fetch_row($var2))
                {
            echo "<option value=\"$row[2]\">$row[0]:$row[1]</option>\n";
                }
        echo "</select></td>";
        echo "<td><input onblur=' javascript:total($i);javascript:global($ligne); ' type=\"text\" name=\"qte_$i\" tabindex=\"7+$i\" value=$qt></td>"; //qte saisie
        echo "<td><input onblur=' javascript:total($i);javascript:global($ligne); ' type=\"text\" name=\"prix_$i\" tabindex=\"7+$i\" value=$pr></td>"; //prix
        echo "<td><input readonly notab type=\"text\" name=\"tot_$i\" size=15 value=$tot></td></tr>";
        echo "<input type=\"hidden\" name=\"fct_$i\">";
        $i=$i+1;
        }
    echo "</table><br>";
    echo "<b>Total de la commande : <input readonly notab type=\"text\" name=\"totglobal\" size=15 value=$totglobal> euros</b><br><br>";
 
    echo "<button type=\"Submit\" name=\"submit2\" value=\"Enregistrer\" onClick='javascript:recenreg();msg(\"$bl\",\"$ligne\");' tabindex=\"8+$ligne\"><img src=\"../enregistrer.gif\"><b> Enregistrer</b></button>";
    echo "<input type=hidden name=\"recenregist\" value=no><input type=\"hidden\" name=\"rep_msg\">";
 
    echo "</form></center>";
 
}
 
    $rep_msg=$_POST['rep_msg'];
    $recenregist=$_POST['recenregist'];
    $magasin=$_POST['magasin'];
    $date=$_POST['date'];
    $nofour=$_POST['nofour'];
    $comment=$_POST['comment'];
    $artic=$_POST['artic'];
    $qt=$_POST['qt'];
    $pr=$_POST['pr'];
    $bl=$_POST['bl'];
    $recsuite=$_POST['recsuite'];
 
    "<SCRIPT LANGUAGE=\"JavaScript\">
    $ligne=document.forms[\"form1\"].elements[\"ligne\"]
    </script>";
    if($recenregist=="yes") //$submit=="Enregistrer"
        {
 
            if($rep_msg==0)
                {
                    echo "<SCRIPT LANGUAGE=\"JavaScript\">alert(\"Ca marche ! Trop Kool ici !\")</script>";        
                    $i=1;
                    while($i<=$ligne)
                        {
                        echo "<SCRIPT LANGUAGE=\"JavaScript\">alert(\"Ca marche ! Trop Kool la !\")</script>";    
                            $art[0]="fct_";
                            $art[1]=$i;
                            $artic=implode($art,"");
                            $artic=$$artic;
                            $art=explode(":",$artic);
                            $artic=$art[0];
                            $q[0]="qte_";
                            $q[1]=$i;
                            $qt=implode($q,"");
                            $qt=$$qt;
                            $p[0]="prix_";
                            $p[1]=$i;
                            $pr=implode($p,"");
                            $pr=$$pr;
                            if(isset($pr,$qt))
                                {
                                    echo "<SCRIPT LANGUAGE=\"JavaScript\">alert(\"Ca marche ! Trop Kool !\")</script>";        
                                    $query_insert=("INSERT INTO commande (destinataire,num_fac,date,fournisseur,commentaire,codeint,quantite,prix) VALUES('$magasin','$bl','$date','$nofour','$comment','$artic','$qt','$pr')");
                                    mysql_query($query_insert) or die("Impossible d'ex&eacute;cuter la requete $query_insert.");
                                }
                            $i=$i+1;
                        }
                    echo"<SCRIPT language=\"javascript\">parent.frames[\"center\"].window.location=\"../centre.php\";</SCRIPT>";
                }
        }
    else { if($recsuite=="yes") echo "<SCRIPT LANGUAGE=\"JavaScript\">alert(\"Vous devez saisir tous les champs !\")</script>"; 
}
 
 
 
 
?>
 
</body>
</html>