So i have a selector wich is based on my Database. Once people select something from that selector, select it and press next. They will see this page:
(Selected train02 in example here)

Code for this is:
<form method="POST" action="add_to_summary.php?user_id=<?php echo $_SESSION['user_id']?>">
<div id="customer_list_table">
<table>
<tr>
<th>Train id</th>
<th>Train Name</th>
<th>Tare Weight</th>
<th>Numbers of bogies</th>
<th>Numbers of axles</th>
</tr>
<?php
foreach($_POST["checkbox"] as $key=>$val){
$data = $database->getAllAssoc_id($val);
foreach($data as $data1) { ?>
<tr>
<input type='hidden' name='user_id[<?php echo $_GET['user_id']?>]' value='<?php echo $_GET['user_id']?>'>
<input type='hidden' name='train_id[<?php echo $data1['train_id']?>]' value='<?php echo $data1['train_id']?>'>
<td><?= $data1['train_id'] ?></td>
<td><?= $data1['train_name'] ?></td>
<td><?= $data1['tare_weight'] ?></td>
<td><?= $data1['number_of_bogies'] ?></td>
<td><?= $data1['number_of_axles'] ?></td>
</tr><?php
}
} ?>
</table>
</div>
<input name="Add to list" type="submit" id="add_to_list" value="Add to list">
</form>
When they press Add to list, an insert gets send to my database like this:
function summary_add($id) {
$sql = "INSERT INTO user_train_information "
. "(train_id, user_id)"
. "VALUES (:train_id, :user_id) ";
$sth = $this->pdo->prepare($sql);
$sth->bindParam(':train_id', $id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $id, PDO::PARAM_STR);
$sth->execute();
}
Code on the add_to_summary.php:
<?php
foreach($_POST['user_id'] as $id) {
$test = $database->summary_add($id);
}
?>
Now, info gets inserted in my DB. but double the one i selected. like this:

And when i change $_POST['user_id'] to $_POST['train_id'] it inputs 14 2 times.
When i just do foreach($_POST as $id), i get 2 array to string conversion errors.
How do i fix this???
I want the table to insert correctly so that the user_id column will be 1, and the train_id column 14
EDIT:
for the selector / selection boxes: form pass selected to next page
EDIT:
It is working right now!
What is changed:
Changed the to hidden fields:
<input type='hidden' name='user_id' value='<?php echo $_GET['user_id']?>'>
<input type='hidden' name='train_id' value='<?php echo $data1['train_id']?>'>
The function:
function summary_add($train_id, $user_id) {
$sql = "INSERT INTO user_train_information "
. "(train_id, user_id)"
. "VALUES (:train_id, :user_id) ";
$sth = $this->pdo->prepare($sql);
$sth->bindParam(':train_id', $train_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->execute();
}
Where i insert it:
<?php
$test = $database->summary_add($_POST['train_id'], $_POST['user_id']);
print_r($_POST);
?>