PHP - sending a full line with one flag and POST

I have a table with rows, which is in the form: ID, Name, Name, IntA, IntB, IntC, ... The last columns are text fields.

I want to select a few lines with a checkbox and send the identifier and the written integers with POST to another PHP file.

This is my sample code (it is a bit German in it):

echo "<td><input type='checkbox' name='auswahl[]' value='$daten[0]'></td>";
echo "<td>" . $daten['ID'] . "</td>";
echo "<td><input type='number' name='Schr' value='".$punkte['PktSchr']."'></td>";
echo "<td><input type='number' name='Mdl' value='".$punkte['PktMdl']."'></td>";

So, in another PHP file, I want SQL for all marked lines like this (in Loop):

$Eintraege  = $_POST['auswahl'];
$Schr       = $_POST['Schr'];
$Mdl        = $_POST['Mdl'];
foreach ($Eintraege as $i){
    $sql = "INSERT INTO aufnahme (IDSchueler, PktSchr, PktMdl) Values ('$i', '$Schr', '$Mdl')";
}

My problem is this: it $Eintraegecontains only the identifiers of the selected rows (due to value='$daten[0]'). $Schrand $Mdlcontains the values ​​of the text fields of the last line (it does not matter which lines are selected).

So, I tried to set value='$daten'and use its lika for the array, but then I get an exception.

, value='$daten[0]', , .

!

+4
2

, .

, : -

echo "<td><input type='number' name='Schr[]' value='".$punkte['PktSchr']."'></td>";
echo "<td><input type='number' name='Mdl[]' value='".$punkte['PktMdl']."'></td>";

, : -

foreach ($Eintraege as $k=> $i){
  $sql = "INSERT INTO aufnahme (IDSchueler, PktSchr, PktMdl) Values ('$i', '$Schr[$k]', '$Mdl[$k]')";
}
+1

@Alive-to-Die, .

<input type='checkbox' name='auswahl[]' value='$daten[0]'>

.

<input type='checkbox' name='auswahl[]' value='{$daten[0]}'>

<input type='checkbox' name='auswahl[]' value='".$daten[0]."'>

.

+1

Source: https://habr.com/ru/post/1688599/


All Articles