I have a form that gets saved to a mysql database.
This is an example of the mutiple checkbox array in the register form:
<input type="checkbox" name="Hobbies[]" value="Antiques" <?php if ($Hobbies[0] == "Antiques") echo "CHECKED" ?>>
<input type="checkbox" name="Hobbies[]" value="Dogs" <?php if ($Hobbies[1] == "Dogs") echo "CHECKED" ?>>
<input type="checkbox" name="Hobbies[]" value="Motorcycles" <?php if ($Hobbies[2] == "Motorcycles") echo "CHECKED" ?>>
<input type="checkbox" name="Hobbies[]" value="Social cause/activism" <?php if ($Hobbies[3] == "Social cause/activism") echo "CHECKED" ?>>
When saving the form, I have this:
$new_Hobbies = implode(",", $_POST['Hobbies']);
Then I save $new_Hobbies in a field of the MySQL table.
When it comes to a client EDITING there information, again I am bringing that information up as:
$Hobbies=explode(",", $new_Hobbies);
<input type="checkbox" name="Hobbies[]" value="Antiques" <?php if ($Hobbies[0] == "Antiques") echo "CHECKED" ?>>
<input type="checkbox" name="Hobbies[]" value="Dogs" <?php if ($Hobbies[1] == "Dogs") echo "CHECKED" ?>>
<input type="checkbox" name="Hobbies[]" value="Motorcycles" <?php if ($Hobbies[2] == "Motorcycles") echo "CHECKED" ?>>
<input type="checkbox" name="Hobbies[]" value="Social cause/activism" <?php if ($Hobbies[3] == "Social cause/activism") echo "CHECKED" ?>>
----PROBLEM----
What is currently happening is that IF the client when registering chooses:
Checkbox 1
Checkbox 2
Checkbox 4
The only boxes that are checked in the edit page is checkbox 1 and 2. Checkbox 4 is not checked.
It seems to fill-in the form fine UNTIL it comes to a blank and then stops showing the checkboxes checked.
Inside the new_Hobbies field is the following:
Antiques,Dogs,Social cause/activism
You will see that since the client DID NOT choose 'Motorcycles', it is not in the database.
Why does it stop at checkbox 3 and not update checkbox 4?
This is driving me crazy.
Any help would be greatly appreciated. Thanks