I wonder how to edit a form with checkboxes.
I have 2 tables in database.
One table with categories and
one table for members
In the edit form for the member, I need to display the categories from the category table, But I also need to check the category checkboxes with the values(array) that are already in the database for one field.
I’m not sure how to do this. I know how to add the checkbox values to the field in the member table, but I don’t really know how to edit them or display them.
Maybe someone can show in the examples I have below.
EDIT FORM FILE
//The "category" table is called "genres" and the below code
//only shows how to get the categories and display them in the checkbox
//The "member" table has a field called "genres" where I need to get the
//values from and display as checked. This is where I'm not sure how to do it
$QUERY6 = mysql_query("SELECT * FROM genres");
$NUMROWS6 = mysql_num_rows($QUERY6);
if ($NUMROWS6) {
$I6 = 0;
while ($I6 < $NUMROWS6) {
$genre_name = mysql_result($QUERY6,$I6,"genre_name");
echo "<input type='checkbox' checked='checked' value='$genre_name' name='genres[]'>$genre_name\
";
$I6++;
}
}
RECEIVING POSTED VALUES FILE
$genres = clean(serialize($_POST[‘genres’]));
DISPLAY FILE
//This file is just example. How do I retreive and display an array from one
//field in the database. I'm not sure how and were to use "unserialize()" in
//the below code
$QUERY7 = mysql_query("SELECT * FROM members");
$NUMROWS7 = mysql_num_rows($QUERY7);
if ($NUMROWS7) {
$I7 = 0;
while ($I7 < $NUMROWS7) {
$genres = mysql_result($QUERY7,$I7,"genres");
echo $genres
$I7++;
}
}