Fixed account type not showing by default on edit

This commit is contained in:
Andrew Malsbury 2023-10-09 21:42:03 +00:00
parent 9c099f7f98
commit bb559a4bdb
1 changed files with 13 additions and 12 deletions

View File

@ -10,7 +10,6 @@
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="account_id" value="<?php echo $account_id; ?>">
<div class="modal-body bg-white">
<div class="form-group">
<label>Account Name <strong class="text-danger">*</strong></label>
<div class="input-group">
@ -20,7 +19,6 @@
<input type="text" class="form-control" name="name" value="<?php echo $account_name; ?>" placeholder="Account name" required>
</div>
</div>
<div class="form-group">
<label>Account Type <strong class="text-danger">*</strong></label>
<div class="input-group">
@ -29,24 +27,27 @@
</div>
<select class="form-control select" name="type" required>
<option value="">- Select -</option>
<!-- If $account_type is set and exists in the array, show it as selected -->
<?php if (isset($account_type) && isset($account_types[$account_type])): ?>
<option value="<?php echo $account_type; ?>" selected><?php echo $account_types[$account_type]; ?></option>
<?php endif; ?>
<?php
$sql_account_type = mysqli_query($mysqli, "SELECT * FROM account_types WHERE account_type_id = $account_type_id");
$row = mysqli_fetch_array($sql_account_type);
$account_type_name = nullable_htmlentities($row['account_type_name']);
echo "<option value='$account_type_id' selected>$account_type_name</option>";
?>
<option value="">----------------</option>
<!-- Loop through the associative array to generate the options -->
<?php foreach ($account_types as $value => $label): ?>
<option value="<?php echo $value; ?>"><?php echo $label; ?></option>
<?php endforeach; ?>
<?php
$sql_account_types = mysqli_query($mysqli, "SELECT * FROM account_types ORDER BY account_type_name ASC");
while ($row = mysqli_fetch_array($sql_account_types)) {
$account_type_id = intval($row['account_type_id']);
$account_type_name = nullable_htmlentities($row['account_type_name']);
if($account_type_id % 10 != 0) {
echo "<option value='$account_type_id'>$account_type_name</option>";}}?>
</select>
</div>
</div>
<div class="form-group">
<label>Notes</label>
<textarea class="form-control" rows="5" placeholder="Enter some notes" name="notes"><?php echo $account_notes; ?></textarea>
</div>
</div>
<div class="modal-footer bg-white">
<button type="submit" name="edit_account" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Save</button>