Currently I'm quite unexperienced with php but needed a little simple program. I've created a little website where some data can be stored (The name of a product, the amount of those products and the price of that products)
I've called it back as a table with in every table row an input(text) field with the containing data.
I need this data to be editable and all be saved with just one press on the button but I just can't get it to work...;(
Here's my current code:
$products_array = array("");
$amounts_array = array("");
$prices_array = array("");
$id_array = array("");
<form method="POST" name="update">
<?php
foreach($object as $objects){
array_push($products_array, $objects['product']);
array_push($amounts_array, $objects['amount']);
array_push($prices_array, $objects['price']);
array_push($id_array, $objects['id']);
echo "<tr>
<td><input type='text' name='".$objects['id']."' value='". $objects['product'] ."'></td>
<td><input type='text' name='".$objects['id']."' value='". $objects['amount'] ."'></td>
<td><input type='text' name='".$objects['id']."' value='". $objects['price'] ."'></td>
</tr>";
}
?>
<input type="submit" value="Opslaan">
</form>
this receives all the rows from the database in text fields and store their data in an array.
This is how I tried to update it:
<?php
if(isset($_POST['update'])){
for($i = 1; $i <= $count; $i++){
$sql = 'UPDATE objects SET product = "$products_array[$i]", amount = "$amounts_array[$i]", price = "$prices_array[$i]" WHERE id = "$id_array[$i]" ';
$sql = $conn->query($sql);
}
unset($_POST);
header('Location: index.php');
}
?>
Anyone has any clue how to fix this or has a better method?
Thanks in advance ^_^