I have multiple table rows output with values populated from a database.
<tr>
<td>
<select name='edit_ativity[]'>
<option value="11" selected="selected">Aerobic Dancing - Low Impact</option>
<option value="12">Aerobic Dancing - Strenuously</option>
<option value="13">Aerobics - High Impact</option>
<option value="19">Skipping - Slow</option>
</select>
</td>
<td>
<input type='text' name='edit_duration[]' value='100' />
</td>
<td>
<input type='text' class='datepicker' name='edit_datepicker[]' value='2019-03-01' id=''>
</td>
</tr>
An other Row
An other Row
The user can change the values on each of the row fields then submit the form which updates the database with the new values.
if(isset($_POST['edit'])) {
foreach ($_POST['edit_ativity'] as $key=>$value) {
$dist_activity_id = $_POST['edit_ativity'][$key];
$dist_activity_duration = $_POST['edit_duration'][$key];
$dist_id = $_POST['distance_id'][$key];
$dist_date = $_POST['edit_datepicker'][$key];
$stmt = $conn->prepare("UPDATE distance SET dist_activity_id=$dist_activity_id, dist_activity_duration=$dist_activity_duration, dist_date='$dist_date' WHERE id=$dist_id");
$stmt->execute();
}
$stmt->close();
mysqli_close($conn);
}
What I need help with is only executing the update command none of fields are empty.
mysqliorPDOissetorempty, this should not be too hard