在PHP和HTML中,我创建了一个组合框,您可以在其中更新值。每当有人选择一条记录时,我都希望所有数据都在表单内。我的文本框全部使用填充
$query = "SELECT * FROM users WHERE username = :id";
$stm = $con->prepare($query);
$stm->bindParam(':id', $id, PDO::PARAM_STR, 20);
$stm->execute();
$result = $stm->fetchAll(PDO::FETCH_OBJ);
foreach ($result as $pers) {
$user2 = $pers->password;
$user4 = $pers->status;
$user5 = $pers->man;
}
<input type="text" name="wachtwoordu" id="wachtwoordu" value="<?php echo htmlspecialchars($user2); ?>"/>
但是组合框没有填充以下值:
<select id="positieu" name="positieu" >
<option value="<?php echo htmlspecialchars($user4); ?>" selected='selected'></option>
<option value="geleider">Geleider</option>
<option value="trainer">Trainer</option>
<option value="commandant">Commandant</option>
<option value="staf">Staf</option>
<option value="arts">Arts</option>
<option value="school">School</option>
<option value="coach">Coach</option>
</select>
<?php
$sql = "SELECT * FROM basissen ORDER BY naam";
$stmt = $con->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll();
?>
<select id="basisu" name="basisu" value="<?php echo htmlspecialchars($user5); ?>">
<?php foreach($result as $pers): ?>
<option value="<?= $pers['naam']; ?>"><?= $pers['naam']; ?></option>
<?php endforeach; ?>
</select>
我希望SQL值是默认值,但它也必须是可用的,因此当我进行更新而不更改时,它将保存默认值。