I have a HTML form that i populate from database with a "foreach" loop, so the fields in the name have the same name. The data that i want to post back into the database comes from variables that are arrays. At this moment when i insert into database, i get the right TIMES of insert, only the values that are inserted (in this case 4 times) are the same values, as in the last row of the HTML form.
I have spent days searching the internet, and rebuilding code, but cant find the solution. I tried implode, even extract values from the VAR, but am sure i am on the wrong track. I am a beginner, just asking to be put back on the right track. Thanks so much...
<?php
if(isset($_GET['submit']))
{
$client_id = ($value->ID);
$qry = "INSERT INTO salesorder (client_id)
VALUES ('$client_id')";
$result=mysqli_query($mysql,$qry) or die(mysqli_error($mysql));
$order_id = mysqli_insert_id($mysql);
foreach ( $results as $result ) :
$food_id = $_GET['foodid']; print_r($food_id);
$qty = $_GET['qty'];
$qry="INSERT INTO orderline (order_id, food_id, qty) VALUES ($order_id, '$food_id', '$qty') ";
$result=mysqli_query($mysql,$qry) ;
endforeach;
}
?>
<tbody>
<form action="" method="GET">
<?php foreach ( $results as $result ) : ?>
<tr><td><input name="qty" size="2" type="number"></td>
<td><?php print($result->food_type); ?></td>
<td><input name="foodid[]" size="4" type="number" value=<?php print($result->food_id); ?>></td><tr>
<?php
endforeach;
?>
</tbody>
this is what the form looks like...
So the form is first dynamic loaded, from the database. could be 2 lines, or 50 lines... but my problem is, after the client fills out qty where he wants to place order off, to "read" the whole form, and load it back into the database