I wanna edit an info of a checkbox in a page but when I clicked the edit link I want the already selected multiple checkbox from the database to be set as checked. But the result I get from my code is that only the last selected checkbox is set as checked(ticked) instead of all the selected checkbox.
Here's my code:
<td><input type = "checkbox" name = "checkbox[]" value = "Badminton" <?php if($interest == 'Badminton') echo "checked = 'checked'"; ?>/>Badminton</td>
<td><input type = "checkbox" name = "checkbox[]" value = "Baseball" <?php if($interest == 'Baseball') echo "checked = 'checked'"; ?>/>Baseball</td>
<td><input type = "checkbox" name = "checkbox[]" value = "Basketball" <?php if($interest == 'Basketball') echo "checked = 'checked'"; ?>/>Basketball</td>
<td><input type = "checkbox" name = "checkbox[]" value = "Cricket" <?php if($interest == 'Cricket') echo "checked = 'checked'"; ?>/>Cricket</td>
<td><input type = "checkbox" name = "checkbox[]" value = "Football" <?php if($interest == 'Football') echo "checked = 'checked'"; ?>/>Football</td>
and heres my sql code:
$sql = "SELECT * FROM interest where username = '$username'";
$result = $conn->query($sql);
if($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$interest = $row['interest_name'];
}
}