我正在构建一个可以在事后编辑的提交表单,并且有一系列提交到数组的复选框,但是当我编辑数据时,我想要先检查先前选中的框。当表单最初提交时,复选框全部进入一个数组,该数组将被内置到数据库中的单个单元格中。这是我到目前为止所做的。
<?php
$query = "SELECT * FROM profile WHERE username = '{$_SESSION['username']}' ";
$result = mysqli_query($connection, $query);
if (!$result) {
$_SESSION["message"] = "You have not built your profile yet.";
redirect_to("my_profile.php");
}
$row = mysqli_fetch_array($result);
$activities = $row['activities'];
?>
<fieldset>
<legend>What kind of activities do you enjoy?</legend><br />
<input type="checkbox" name="activities[]" value="sailing"/>Sailing
<input type="checkbox" name="activities[]" value="hiking"/>Hiking
<input type="checkbox" name="activities[]" value="gaming"/>Gaming<br />
<input type="checkbox" name="activities[]" value="mountain_biking"/>Mountain Biking
<input type="checkbox" name="activities[]" value="food"/>Food
<input type="checkbox" name="activities[]" value="travel"/>Travel<br />
<input type="checkbox" name="activities[]" value="paintball"/>Paintball
<input type="checkbox" name="activities[]" value="computers"/>Computers
</fieldset>