formulier in foreach loops
formulier:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
echo "<form method=\"post\" action=\"index.php\"><table border=0 cellspacing=0 cellpadding=0 width=100%>";
$i=0;
while ($i<$nmb){
echo "
<tr>
<td valign=top><input type=\"checkbox\" id=\"cb$i\" name=\"cid[]\" value=\"".$belegid[$i]."\" onClick=\"isChecked(this.checked);\" /></td>
<td valign=top>".$beleg[$i]."</td>
<td valign=top><input type=\"text\" name=\"aantal\" value=\"\" size=\"7\"><input type=\"hidden\" name=\"broodid\" value=\"".$broodid[$i]."\"></td>
<td valing=top><b> ".$prijs[$i]."</b><input type=\"hidden\" name=\"prijs\" value=\"".$prijs[$i]."\"></td>
</tr>\n";
$i++;
}
echo "<tr><td colspan=4><input type=\"submit\" value=\"Leg in mandje\" name=\"save\"></td></tr></table></form>";
}
$i=0;
while ($i<$nmb){
echo "
<tr>
<td valign=top><input type=\"checkbox\" id=\"cb$i\" name=\"cid[]\" value=\"".$belegid[$i]."\" onClick=\"isChecked(this.checked);\" /></td>
<td valign=top>".$beleg[$i]."</td>
<td valign=top><input type=\"text\" name=\"aantal\" value=\"\" size=\"7\"><input type=\"hidden\" name=\"broodid\" value=\"".$broodid[$i]."\"></td>
<td valing=top><b> ".$prijs[$i]."</b><input type=\"hidden\" name=\"prijs\" value=\"".$prijs[$i]."\"></td>
</tr>\n";
$i++;
}
echo "<tr><td colspan=4><input type=\"submit\" value=\"Leg in mandje\" name=\"save\"></td></tr></table></form>";
}
Opslaan in database
Code (php)
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
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
<?php
echo '
<form method="post" action="index.php">
<table border=0 cellspacing=0 cellpadding=0 width=100%>';
for($i = 0; $i < $nmbl $i++) {
echo '
<tr>
<td valign=top>
<input type="checkbox" id="cb' . $i . '" name="cid[' . $i . ']" value="' . $belegid[$i] . '" onClick="isChecked(this.checked)" />
</td>
<td valign=top>
' . $beleg[$i] . '
</td>
<td valign=top>
<input type="text" name="aantal[' . $i . ']" value="" size="7">
<input type="hidden" name="broodid[' . $i . ']" value="' . $broodid[$i] . '">
</td>
<td valing=top>
<b>€ ' . $prijs[$i] . '</b>
<input type="hidden" name="prijs[' . $i . ']" value="' . $prijs[$i] . '">
</td>
</tr>';
}
echo '
<tr>
<td colspan=4>
<input type="submit" value="Leg in mandje" name="save">
</td>
</tr>
</table>
</form>';
?>
echo '
<form method="post" action="index.php">
<table border=0 cellspacing=0 cellpadding=0 width=100%>';
for($i = 0; $i < $nmbl $i++) {
echo '
<tr>
<td valign=top>
<input type="checkbox" id="cb' . $i . '" name="cid[' . $i . ']" value="' . $belegid[$i] . '" onClick="isChecked(this.checked)" />
</td>
<td valign=top>
' . $beleg[$i] . '
</td>
<td valign=top>
<input type="text" name="aantal[' . $i . ']" value="" size="7">
<input type="hidden" name="broodid[' . $i . ']" value="' . $broodid[$i] . '">
</td>
<td valing=top>
<b>€ ' . $prijs[$i] . '</b>
<input type="hidden" name="prijs[' . $i . ']" value="' . $prijs[$i] . '">
</td>
</tr>';
}
echo '
<tr>
<td colspan=4>
<input type="submit" value="Leg in mandje" name="save">
</td>
</tr>
</table>
</form>';
?>
en dan afwerken (merk op dat ik intval gebruik om ervoor te zorgen dat er altijd een nummertje in de db komt)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
foreach($_POST['cid'] AS $i => $cid){
$query="INSERT INTO tijdelijkmand (
mand_klant_id,
mand_uid,
mand_brood_id,
mand_beleg_id,
mand_aantal,
mand_prijs
) VALUES (
'',
'',
" . intval($_POST['broodid'][$i]) . ",
" . intval($cid) . ",
" . intval($_POST['aantal'][$i]) . ",
'" . mysql_real_escape_string($_POST['prijs'][$i]) . "'
)";
$lvlins = mysql($database,$query);
echo $query;
}
?>
foreach($_POST['cid'] AS $i => $cid){
$query="INSERT INTO tijdelijkmand (
mand_klant_id,
mand_uid,
mand_brood_id,
mand_beleg_id,
mand_aantal,
mand_prijs
) VALUES (
'',
'',
" . intval($_POST['broodid'][$i]) . ",
" . intval($cid) . ",
" . intval($_POST['aantal'][$i]) . ",
'" . mysql_real_escape_string($_POST['prijs'][$i]) . "'
)";
$lvlins = mysql($database,$query);
echo $query;
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Jelmer -
Er waren toch klein foutje in..maar is inmiddels opgelost.