mardi 1 septembre 2015

checkboxes checked by default from string or array values

I'm building a submit form that can be edited after the fact and have a series of checkboxes that submit to an array but when I edit the data I'd like to have the boxes previously selected checked already. When the form is initially submitted the checkboxes all go into an array that gets implode to be put into a single cell in the database. This is what I have so far.

<?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> 




Aucun commentaire:

Enregistrer un commentaire