There are three options in the drop-down list:
When I select "Deploy" it saves correctly. When I select "Not Deployed" it saves as "Fault" When I select "Faulty" it saves as "Faulty"
Can you please help me fix this issue so that the form is saved with only the selected options. Thanks.
</div> </div> <?php if(isset($vehicledetails[0]['v_is_active'])) { ?> <div class="col-sm-6 col-md-3"> <div class="form-group"> <label for="v_is_active" class="form-label">Machinery Status</label> <select id="v_is_active" name="v_is_active" class="form-control " required=""> <option value="">Select Machinery Status</option> <option <?php echo (isset($vehicledetails) && $vehicledetails[0]['v_is_active']==1) ? 'selected':'' ?> value="1">Deployed</option> <option <?php echo (isset($vehicledetails) && $vehicledetails[0]['v_is_active']==0) ? 'selected':'' ?> value="0">Not Deployed</option> <option <?php echo (isset($vehicledetails) && $vehicledetails[0]['v_is_active']==0) ? 'selected':'' ?> value="0">Faulty</option> </select> </div> </div> <?php } ?>
Can you please help me fix this issue so that the form is saved with only the selected options.
I assume you have a $vehicledetails data array like
So the problem with your code is that you are repeating the same condition for each of the three options.
So if any condition is met, all options will appear checked.
The conditions for each option should be updated to reflect the appropriate value in $vehicledetails[0]['v_is_active'].
Additionally, the values for the "Not Deployed" and "Faulted" options appear to be incorrect as they both have a value of 0.
Modified code:
Hope this helps.