Good evening everyone! I have a loop that writes data to the database through while () ($ id is known earlier)

$i = 1; while (isset($_POST['account-'.$i]) && isset($_POST['brokerage-id-'.$i])) { $account = $_POST['account-'.$i.'']; $brokerage = $_POST['brokerage-id-'.$i.'']; echo $_POST['account-'.$i.'']; echo $_POST['brokerage-id-'.$i.'']; echo $id; $res = $db->query("INSERT INTO `accounts` SET `id_user` = '".$id."', `account` = '".$account."', `brokerage` = '".$brokerage."'") or exit(mysql_error()); $i++; } 

echo displays everything correctly, but only one record gets into the database (the very first one), but the following ones do not, only echo shows that iterations pass and displays the values ​​of all iterations

  • What is $id ? - PinkTux
  • $ id is the user ID, it is known before, and during the iteration the output is the same value (I thought that it will also change) - Valentin Tikhomirov
  • Nothing happens by itself. you have to follow it yourself since you don’t use the automatic numbering capabilities on the database side (and you don’t need to mention the id in the query at all, so what would the column be autoincrement). In general, after any access to the database, it is necessary to check the exit code and print errors if the DB returned them - Mike
  • there is a possibility that the id field in the database is checked for uniqueness or something else. Show show create table accounts - Pavel Gribov
  • thanks for the replies) I found the reason) - Valentin Tikhomirov

0