0

I got the following issue while trying to insert multiple entries into a 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)

i.e. $r = 7 $s = 3 gives me 21 slots which is correct.

$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();

Tarek
  • 3,810
  • 3
  • 36
  • 62
Roman Bartel
  • 3
  • 1
  • 4
  • If you need to insert multiple rows into the database, you should use the `implode()` function available in PHP. [See](http://stackoverflow.com/questions/779986/insert-multiple-rows-via-a-php-array-into-mysql). – Lion Apr 11 '12 at 11:22

3 Answers3

2

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 '='.

Armatus
  • 2,206
  • 17
  • 28
1
 $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());
Glenn
  • 489
  • 2
  • 7
  • 19
0

You don't have an "=" after $slot, but $platz does.

Stefan Manciu
  • 490
  • 1
  • 6
  • 19