【发布时间】:2012-04-23 16:22:44
【问题描述】:
我在尝试将多个条目插入 MySQL innodb 时遇到以下问题。
只有第一个插入存储在数据库中。 (虽然它的存储是正确的)
db数据正确,post数据正确,一切都经过测试 while 循环在我的测试中计数正确(没有插入)
即$r = 7 $s = 3 给了我 21 个插槽,这是正确的。
$l = $_POST['Lager'];
$r = $_POST['Reihe'];
$p = $_POST['platz'];
$s = $_POST['slots'];
$a = $_POST['art'];
echo( "test: " . $_POST['Lager'] . $_POST['Reihe'] . $_POST['platz'] . $_POST['slots'] . $_POST['art'] );
$i=0;
$n=0;
$counter =0;
while($i < $p)
{
$platz =("
INSERT INTO
Lager (LagerNr,ReiheNr,PlatzNr,SlotNr,LagerArt,Stock)
VALUES ('". $l ."','" . $r . "','" . $i . "','". $n ."','" . $a . "','0')");
mysql_query($platz);
echo ($platz);
// anzahl slots = $s
while($n < $s)
{
$slot("
INSERT INTO
Lager (LagerNr,ReiheNr,PlatzNr,SlotNr,LagerArt,Stock)
VALUES ('". $l ."','" . $r . "','" . $i . "','". $n ."','" . $a . "','0')");
mysql_query($slot) OR print(mysql_error());
$n++;
$counter++;
echo($slot);
}
$n = 0;
$i++;
}
echo ("\n" . $counter . " Slots erstellt");
mysql_close();
【问题讨论】:
-
如果你需要在数据库中插入多行,你应该使用 PHP 中的
implode()函数。 See.
标签: php mysql loops insert while-loop