lundi 13 avril 2015

Update via loop

When users fill in a form they also fill in the number of axles. the information gets send to the table: "train_information" when submitted. The row axles is a FK and also gets send in the table "axle". The table axle looks like this after insert:


database table


Now i want to be able to update the distance (Wich is NULL right now). I do this by showing the number of axles and make a field box of them:



<tr>
<?php
foreach($show_axle as $axleposition){ ?>
<input type='hidden' name='axle_id' value='<?php echo $axleposition['axle_id']?>'>
<td><input type='text' name='distance' id = "<?php echo $axleposition['axle_id']?>"placeholder="<?php echo $axleposition['axle']?>"></td>

<?php
}
?>
</tr>


As you can see i show it in a form. The form action is:



<form method='POST' action='axle_update.php'>


So when they press submit, they go to axle_update.php wich looks like this:



<?php
?><pre><?php print_r($_POST) ?> </pre> <?php

$update_axle = $database->update_axles();
?>


(The pre is for myself to see what gets send)


This kinda works. becuase when i have for example 12 rows (See image). it only updates the last row. Now this is because the name of the hidden field is the same everywhere. But i don't know how to change that (In the query).


Aucun commentaire:

Enregistrer un commentaire