Something very strange is happening here. This code below (automatic input values after dropdown selection) does not get saved in the database with 1 click on submit but after 2 clicks. Is there a simple fix for this or do I need an different approach here?
<?php $id = (ISSET($_GET['client'])) ? intval($_GET['client']):0; ?>
<?php while ($row = $result->fetch_assoc()) {?>
<form class="edit" action="" method="post">
<?php
$a = $row['costs'];
$b = $row['deposit'];
$c = $a-$b;
$auto6 = $a*1.06;
$auto21 = $a*1.21;
?>
<select id="btw" name="btw" class="input-xlarge">
<option value="Verlegd"<?=$row['btw'] == 'Verlegd' ? ' selected="selected"' : '';?>>Verlegd</option>
<option value="6%"<?=$row['btw'] == '6%' ? ' selected="selected"' : '';?>>6%</option>
<option value="21%"<?=$row['btw'] == '21%' ? ' selected="selected"' : '';?>>21%</option>
</select>
<strong>Total excl BTW:</strong><input id="btw0" class="special <?=$row['btw'] != 'Verlegd' ? 'disabled' : 'enabled';?>" type="text" name="exclbtw" value="<?=$row['btw'] == 'Verlegd' ? $a : '';?>">
<strong>Total incl BTW 21%:</strong><input id="btw21" class="special <?=$row['btw'] != '21%' ? 'disabled' : 'enabled';?>" type="text" name="btw21" value="<?=$row['btw'] == '21%' ? $auto21 : '';?>">
<strong>Total incl BTW 6%:</strong><input id="btw6" class="special <?=$row['btw'] != '6%' ? 'disabled' : 'enabled';?>" type="text" name="btw6" value="<?=$row['btw'] == '6%' ? $auto6 : '';?>">
<INPUT TYPE="Submit" VALUE="Save" NAME="Submit">
</form>
<?php } ?>
<?php
if(isset($_POST['Submit'])){
$btw = $_POST['btw'];
$exclbtw = $_POST['exclbtw'];
$btw21 = $_POST['btw21'];
$btw6 = $_POST['btw6'];
$update = "UPDATE
invoice
SET
btw = '$btw',
exclbtw = '$exclbtw',
btw21 = '$btw21',
btw6 = '$btw6'
WHERE
id = $id";
$conn->query($update) or die("Cannot update");
}
?>
<?php
if($update){//if the update worked
echo("<script>window.location = 'http://example.com/invoice/edit.php?client=$id';</script>");
} else {
"Error";
}
?>