Toon posts:

[PHP] array + POST probleem

Pagina: 1
Acties:
  • 50 views sinds 30-01-2008

Verwijderd

Topicstarter
Beste jongelui, ik zit met een probleempje..

Ik ben net begonnen met PHP en nu loop ik vast op het volgende. Ik heb een paar puldown menu's gemaakt waaruit de gebruiker zijn keuze kan maken. Daarachter geeft hij aan hoeveel van deze producten hij wil hebben. Hierna drukt de gebruiker op de "verzend" knop. Nu zou er wat in mijn scherm moeten komen, maar er gebeurt nix. Waar zit mijn fout in de onderstaande code. (PS is moet met POST werken)

$blabla = $_POST['blabla'];

zoiets moet het zijn geloof ik.. Maar waar moet ik dit neerzetten en hoe werkt het verder??


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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<html>
<head>
<title>PHP week 2</title>

</head>

<body>
<table width="340" border="1" cellpadding="5" bgcolor="#00CCFF">
  <tr> 
    <td width="50%"> 
      <?php
    

    // Maak het formulier aan:
    print ("<form action=\"$PHP_SELF\" method=post>\n");
    
// Maak de 12 maanden aan (NED):

print ("<tr><td><font size = 2 face=Verdana>Kies Maand</font><br>\n");
print ("<select name=maand><OPTION>Kies</OPTION>\n");

$emaand = 1;
while ($emaand <= 12){
    print ("<OPTION VALUE=$emaand>$emaand</OPTION>\n");
$emaand++;

}

print ("</SELECT>\n");
    
//maak de dagen aan:
    print ("<p><font size = 2 face=Verdana>Kies een dag:</font><br>\n");
    print ("<select name = dag><option>Kies</option>\n");
        
    $dag = 1;
    while ($dag <=31){
    print ("<option value = $dag>$dag</option>\n");
    $dag++;
    }
    
    print ("</select>\n");
    
    
// Maak de jaren aan:
    print ("<p><font size = 2 face=Verdana>Kies een jaar:</font><br>\n");
    print ("<select name = jaar><option>Kies</option>\n");
    
    $jaar = 1978;
    while ($jaar <=2010){
    print ("<option value = $jaar>$jaar</option>\n");
    $jaar++;
    }
    
    print ("</select>\n");
    

// Maak de taalkeuzes aan:
    print ("<p><font size = 2 face=Verdana>Kies Taal | Choose Language:</font><br>\n");
    print ("<select name = taal><option>Kies | Choose</option>\n");
    print ("<option value = nederlands>Nederlands</option>\n");
    print ("<option value = engels>English</option>\n");    
    
    print ("</select>\n");

    ?>
        
    </td>
  </tr>

</table>
<br>
<table width="524" border="1" cellpadding="5" bgcolor="#0099CC">
  <tr> 
    <td width="247"> 
      <?php

// Maak het formulier aan:
    print ("<form action=\"$PHP_SELF\" method=get>\n");
    
// Maak product 1 aan:
    print ("<p><font size = 2 face=Verdana>Kies een zuivelproduct uit ons assortiment</font><br>\n");
    print ("<select name = product1><option>Kies een zuivelproduct</option>\n");
    print ("<OPTION VALUE=1>Melk </OPTION>\n");
    print ("<OPTION VALUE=2>Karnemelk </OPTION>\n");
    print ("<OPTION VALUE=3>Yoghurt </OPTION>\n");
    print ("<OPTION VALUE=4>Vla </OPTION>\n");
    print ("<OPTION VALUE=5>Kaas </OPTION>\n");
    
    print ("</select>\n");

    
    
// Maak product 2 aan:
    print ("<p><font size = 2 face=Verdana>Kies een brood uit het assortiment</font><br>\n");
    print ("<select name = product2><option>Kies een brood</option>\n");
    print ("<OPTION VALUE=1>Volkoren </OPTION>\n");
    print ("<OPTION VALUE=2>Grof volkoren </OPTION>\n");
    print ("<OPTION VALUE=3>Pain de Bologne </OPTION>\n");
    print ("<OPTION VALUE=4>Bolletje(s) </OPTION>\n");
    print ("<OPTION VALUE=5>Puntje(s) </OPTION>\n");
    
    print ("</select>\n");
    
    
// Maak product 3 aan:
    print ("<p><font size = 2 face=Verdana>Kies een streekproduct uit het assortiment</font><br>\n");
    print ("<select name = product2><option>Kies een streekproduct</option>\n");
    print ("<OPTION VALUE=1>Boerenjongens (20%) </OPTION>\n");
    print ("<OPTION VALUE=2>Groninger Koek </OPTION>\n");
    print ("<OPTION VALUE=3>Groninger Worst </OPTION>\n");
    print ("<OPTION VALUE=4>Groninger Kaas </OPTION>\n");
    print ("<OPTION VALUE=5>Groninger Achterham </OPTION>\n");
    
    print ("</select>\n");
    
// Maak product 4 aan:
    print ("<p><font size = 2 face=Verdana>Kies een boek uit het assortiment</font><br>\n");
    print ("<select name = product2><option>Kies een product</option>\n");
    print ("<OPTION VALUE=1>'Het Groningerland per fiets' </OPTION>\n");
    print ("<OPTION VALUE=2>'De weidevogels' </OPTION>\n");
    print ("<OPTION VALUE=3>'GroningerLandschapgids' </OPTION>\n");
    print ("<OPTION VALUE=4>'Varen door Groningen' </OPTION>\n");
    print ("<OPTION VALUE=5>'Het Westerkwartier' </OPTION>\n");
    
    print ("</select>\n");
    
    
// maak array voor Maand
    $arraymaand[Nederlands][1] ="Januari"; 
    $arraymaand[Nederlands][2] ="Februari"; 
    $arraymaand[Nederlands][3] ="Maart";
    $arraymaand[Nederlands][4] ="April";
    $arraymaand[Nederlands][5] ="Mei";
    $arraymaand[Nederlands][6] ="Juni";
    $arraymaand[Nederlands][7] ="Juli";
    $arraymaand[Nederlands][8] ="Augustus"; 
    $arraymaand[Nederlands][9] ="September"; 
    $arraymaand[Nederlands][10] ="Oktober"; 
    $arraymaand[Nederlands][11] ="November"; 
    $arraymaand[Nederlands][12] ="December";
 
    $arraymaand[Engels][1] ="January"; 
    $arraymaand[Engels][2] ="February"; 
    $arraymaand[Engels][3] ="March";
    $arraymaand[Engels][4] ="April";
    $arraymaand[Engels][5] ="May";
    $arraymaand[Engels][6] ="June";
    $arraymaand[Engels][7] ="July";
    $arraymaand[Engels][8] ="Augustus"; 
    $arraymaand[Engels][9] ="September"; 
    $arraymaand[Engels][10] ="October"; 
    $arraymaand[Engels][11] ="November"; 
    $arraymaand[Engels][12] ="December";    
    

//maak array voor produkt1

$arrayproduct1[Nederlands][1] ="Melk";
$arrayproduct1[Nederlands][2] ="Karnemelk";
$arrayproduct1[Nederlands][3] ="Yoghurt";
$arrayproduct1[Nederlands][4] ="Vla";
$arrayproduct1[Nederlands][5] ="Kaas";

$arrayproduct1[Engels][1] ="Melk - engels";
$arrayproduct1[Engels][2] ="Karnemelk - engels";
$arrayproduct1[Engels][3] ="Yoghurt - engels";
$arrayproduct1[Engels][4] ="Vla - engels";
$arrayproduct1[Engels][5] ="Kaas - engels";
    
    
    
//maak array voor produkt2

$arrayproduct2[Nederlands][1] ="Volkoren";
$arrayproduct2[Nederlands][2] ="Grof volkoren";
$arrayproduct2[Nederlands][3] ="Pain de Bologne";
$arrayproduct2[Nederlands][4] ="Bolletje(s)";
$arrayproduct2[Nederlands][5] ="Puntje(s)";

$arrayproduct2[Engels][1] ="Volkoren - engels";
$arrayproduct2[Engels][2] ="Grof volkoren - engels";
$arrayproduct2[Engels][3] ="Pain de Bologne - engels";
$arrayproduct2[Engels][4] ="Bolletje(s) - engels";
$arrayproduct2[Engels][5] ="Puntje(s) - engels";



//maak array voor Product3

$arrayproduct3[Nederlands][1] ="Boerenjongens (20%)";
$arrayproduct3[Nederlands][2] ="Groninger Koek";
$arrayproduct3[Nederlands][3] ="Groninger Worst";
$arrayproduct3[Nederlands][4] ="Groninger Kaas";
$arrayproduct3[Nederlands][5] ="Groninger Achterham";

$arrayproduct3[Engels][1] ="Boerenjongens (20%) - engels";
$arrayproduct3[Engels][2] ="Groninger Koek - engels";
$arrayproduct3[Engels][3] ="Groninger Worst - engels";
$arrayproduct3[Engels][4] ="Groninger Kaas - engels";
$arrayproduct3[Engels][5] ="Groninger Achterham - engels";
    


//maak array voor Product4

$arrayproduct4[Nederlands][1] ="Het Groningerland per fiets";
$arrayproduct4[Nederlands][2] ="De weidevogels";
$arrayproduct4[Nederlands][3] ="GroningerLandschapgids";
$arrayproduct4[Nederlands][4] ="Varen door Groningen";
$arrayproduct4[Nederlands][5] ="Het Westerkwartier";

$arrayproduct4[Engels][1] ="Het Groningerland per fiets - engels";
$arrayproduct4[Engels][2] ="De weidevogels - engels";
$arrayproduct4[Engels][3] ="GroningerLandschapgids - engels";
$arrayproduct4[Engels][4] ="Varen door Groningen - engels";
$arrayproduct4[Engels][5] ="Het Westerkwartier - engels";


?>
    </td>
    <td width="245"> 
      <?php

// Maak het formulier aan:
    print ("<form action=\"$PHP_SELF\" method=post>\n");

//aantal producten van product1

    print ("<p><font size = 2 face=Verdana>Kies aantal product1:</font><br>\n");
    print ("<select name = aantal_product1><option>Kies</option>\n");

    $aantal_product1 = 1;
    while ($aantal_product1 <=100){
    print ("<option value = $aantal_product1>$aantal_product1</option>\n");
    $aantal_product1++;
    }

    print ("</select>\n");
        
//aantal producten van product2

    print ("<p><font size = 2 face=Verdana>Kies aantal product2:</font><br>\n");
    print ("<select name = aantal_product2><option>Kies</option>\n");

    $aantal_product2 = 1;
    while ($aantal_product2 <=100){
    print ("<option value = $aantal_product2>$aantal_product2</option>\n");
    $aantal_product2++;
    }

    print ("</select>\n");
    
//aantal producten van product3

    print ("<p><font size = 2 face=Verdana>Kies aantal product3:</font><br>\n");
    print ("<select name = aantal_product3><option>Kies</option>\n");

    $aantal_product3 = 1;
    while ($aantal_product3 <=100){
    print ("<option value = $aantal_product3>$aantal_product3</option>\n");
    $aantal_product3++;
    }

    print ("</select>\n");
    
//aantal producten van product4

    print ("<p><font size = 2 face=Verdana>Kies aantal product4:</font><br>\n");
    print ("<select name = aantal_product4><option>Kies</option>\n");

    $aantal_product4 = 1;
    while ($aantal_product4 <=100){
    print ("<option value = $aantal_product4>$aantal_product4</option>\n");
    $aantal_product4++;
    }

    print ("</select>\n");

?>
    </td>
  </tr>
  <tr> 
    <td colspan="2"> 
    <?php
        print ("<P><INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=\"Verzend\"></FORM>\n");

If ($Taal){
    If ($Taal == "nederlands"){
        Print ("Beste bezoeker,<br>");
        Print ("De volgende zaken zitten in uw winkelmandje<br><br>");
        
}
Else{
Print ("Dear visitor,<br>");
Print ("The following products are in your shoppingbasket<br><br> ");


}
}



// controlleren welke taal en print in juiste taal  
Print ("<BR>");

Print ($Dag);
Print (" ");
Print ($arraymaand[$Taal][$Maand] );
Print (" ");
Print ($Jaar);


Print (" ");
Print ($arrayproduct1[$Taal][$Product_1]);


// controleer de taal om de aantallen in de juiste taal weer te geven

If ($Taal){
    If ($Taal == "Nederlands"){
    
        Print (" Aantal : ");
        Print ($aantal_product1);

}
Else{

Print (" Quantaty: ");
Print ($aantal_product1);

}
}

Print (" ");
Print ($arrayproduct2[$Taal][$Product2]);

If ($Taal){
    If ($Taal == "Nederlands"){

        Print (" Aantal : ");
        Print ($aantal_product2);

}
Else{

Print (" Quantaty: ");
Print ($aantal_product2);

}
}

Print ("<TR>");
Print("<TD>");
Print (" ");
Print ($arrayproduct3[$Taal][$Product3]);

If ($Taal){
    If ($Taal == "Nederlands"){

        Print (" Aantal : ");
        Print ($aantal_product3);

}
Else{

Print (" Quantaty: ");
Print ($aantal_product3);

}
}
    ?>
        
    </td>
  </tr>
</table>
</body>
</html>

  • 0528973
  • Registratie: Juni 2003
  • Laatst online: 15-05-2013
Sorry, was nog niet helemaal wakker.

voeg dit eens aan het begin van je script toe(direct onder de body tag bijv.):
PHP:
1
2
3
4
5
6
7
8
<?php
echo "<hr>".$_SERVER["REQUEST_METHOD"]."<hr>";
if($_SERVER["REQUEST_METHOD"] == "POST") {
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
?>


indien je nu op je pagina via een post aanroep aankomt, wordt de $_POST
array op het scherm gezet en kan je dus controleren of het juiste er in zit.
Tevens zie je via watvoor een aanroep je op je pagina aankomt.(GET of POST over het algemeen)

[ Voor 133% gewijzigd door 0528973 op 19-02-2004 11:14 ]

Pascal


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Mja, we doen hier niet een spelletje "dump de code en de oplossing komt wel", hoor. Hou je volgende keer maar even aan de quickstart, en doe een beetje beter je best alleen de relevante zaken te noemen.

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Dit topic is gesloten.