Universal Email IF statement to compare form input with database value before sending email
I have a few automated emails set up on a record update page. Different emails are sent depending on which checkboxes are ticked. I've wrapped each email code with IF statements so that the emails are only sent under conditions, for example the following email is only sent if the OrderSigned and ContractSigned boxes are checked and AERemoved, FactFind and DataTemplate are all unchecked:
<?php if(isset($_POST['OrderSigned']) && $_POST['OrderSigned'] =="1" && ($_POST['ContractSigned'] != "1") && ($_POST['AERemoved'] != "1") && ($_POST['FactFind'] != "1") && ($_POST['DataTemplate'] != "1")) { ?>
[Email code]
<?php } ?>
The form records the progress of an application so only one box is ticked per update, for example the first update would have OrderSigned ticked, the next update would have ContractSigned ticked and so on. However this means that users must tick the boxes in a specific order, otherwise the wrong emails will be generated - for example, if the user ticked ContractSigned the relevant email would be sent, but if they then ticked OrderSigned, the ContractSigned email would be sent again because the value is already "1".
A better way of doing this would be to compare input values with existing database values, so for example the user ticks ContractSigned and updates the record, the IF statement checks to see if ContractSigned is already "1" in the database and only sends the email if the value is "0". Does that make sense? How would I alter my code to do this?