[英]insert into mysql db with php while loop
嘗試將多個條目插入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();
我不完全了解您要執行的操作和無效的操作,但這是:
$slot("
INSERT INTO
Lager (LagerNr,ReiheNr,PlatzNr,SlotNr,LagerArt,Stock)
VALUES ('". $l ."','" . $r . "','" . $i . "','". $n ."','" . $a . "','0')");
似乎缺少一個'='。
$slot("
INSERT INTO
Lager (LagerNr,ReiheNr,PlatzNr,SlotNr,LagerArt,Stock)
VALUES ('". $l ."','" . $r . "','" . $i . "','". $n ."','" . $a . "','0')");
mysql_query($slot) OR print(mysql_error());
應該:
$slot =
("INSERT INTO
Lager (LagerNr,ReiheNr,PlatzNr,SlotNr,LagerArt,Stock)
VALUES ('". $l ."','" . $r . "','" . $i . "','". $n ."','" . $a . "','0')");
mysql_query($slot) OR print(mysql_error());
$ slot之后沒有“ =”,但是$ platz有。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.