I got stuck because I can't update my mysql table using multiple form rows. Currently only the first row works. Basically I would like the person in charge to choose the id to update, enter it and automatically my table will be updated. The next step is that I can get an email with a list of the fields he has updated.
Thank you
index.php
<div class="row">
<h2>Imposta quantità di stampa Dataplate</h2>
<?php
$quantitad_form = $rows['quantita_d'];
$quantitae_form = $rows['quantita_e'];
$id_form = $rows['emp_id'];
?>
<form method = "post" action = "update.php">
<div class="jumbotron jumbotron-fluid" id="dataAdd">
<div class="container-fluid big-container">
<div class="form-row check">
<div class="form-group col-md-4">
<label>ID</label>
<input name = "id_form[]" value = "$id_form" type = "number" id = "id_form1" class="form-control">
</div>
<div class="form-group col-md-4">
<label>Totale Dataplate</label>
<input name="quantitad_form[]" value = "$quantitad_form" type="number" id = "quantitad_form2" class="form-control variable-field quantity"/>
</div>
<div class="form-group col-md-4">
<label>Totale Energy Label</label>
<input name="quantitae_form[]" value = "$quantitae_form" type="number" id = "quantitae_form2" class="form-control width-80 totalcostprice" readonly/>
</div>
</div>
</div>
<div class="container-fluid">
<button type="button" class="btn btn-success" id="addRow">Aggiungi Riga</button>
<button type="button" class="btn btn-danger" id="deleteRow">Cancella Riga</button>
<button name = "update" type = "submit" class="btn btn-danger" id="deleteRow">AGGIORNA</button>
</div>
</div>
</form>
</div>
update.php
<?php
<?php
include_once("db_connect.php");
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
for ($i = 0; $i < count($_POST["quantitad_form"]); $i++) {
$id_form = $_POST["id_form"][$i];
$quantitad_form = $_POST["quantitad_form"][$i];
$quantitae_form = $_POST["quantitae_form"][$i];
$sql = "UPDATE emp SET quantita_d='$quantitad_form', quantita_e='$quantitae_form' WHERE emp_id='$id_form'";
}
/*
if ($conn->query($sql) === TRUE) {
$update_status = '?update_status=success';
} else {
$update_status = '?update_status=error';
}
$conn->close();
header("Location: index.php".$update_status);
*/
?>
Thank you all for your helpfulness, this is the full link https://unical.atena.net/