简体   繁体   English

用php while循环插入mysql数据库

[英]insert into mysql db with php while loop

I got the following issue while trying to insert multiple entries into a MySQL innodb. 尝试将多个条目插入MySQL innodb时遇到以下问题。

only the first insert is stored in the db. 只有第一个插入存储在数据库中。 (although its stored correct) (尽管其存储正确)

db data are correct, post data are correct, everything is tested the while loop is counting correct in my test (without the inserts) db数据正确,post数据正确,一切都经过测试,而while循环在我的测试中计数正确(没有插入)

ie $r = 7 $s = 3 gives me 21 slots which is correct. 即$ 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(); mysql_close();

I don't exactly understand what you are trying to do and what's not working, however this: 我不完全了解您要执行的操作和无效的操作,但这是:

$slot("
 INSERT INTO 
    Lager (LagerNr,ReiheNr,PlatzNr,SlotNr,LagerArt,Stock)
 VALUES ('". $l ."','" . $r  . "','" . $i . "','". $n ."','" . $a . "','0')");

seems to be missing a '='. 似乎缺少一个'='。

 $slot("
 INSERT INTO 
    Lager (LagerNr,ReiheNr,PlatzNr,SlotNr,LagerArt,Stock)
 VALUES ('". $l ."','" . $r  . "','" . $i . "','". $n ."','" . $a . "','0')");
 mysql_query($slot) OR print(mysql_error());

should be: 应该:

 $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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM